Jump to content

Collision check for one sprite


Horizonicblue
 Share

Recommended Posts

6 hours ago, Arcanorum said:

Sprite body pairs are checked against each other. That is just how collision works. If I am colliding with you, then you must also be colliding with me.

What exactly do you have in mind when you say you only want a one way check?

That's true

What I want to do is, suppose if car1 collides with car2, then I want car1 to get killed 

and if car2 collides with car1, then I want car2 to get killed.

 

Is there any other way I can do this?

Link to comment
Share on other sites

It sounds like you want to check which car is moving when a collision happens, as if only one car can be moving at once. You will just need to check the velocity of each car when the callback is called. If one of the cars has a velocity in either x or y that is not 0, then that car is the one that is moving, so remove that car, or the other car.

Both objects are given to the callback as the first and second parameters. See the use of obj1 and obj2 in this example. https://phaser.io/examples/v2/arcade-physics/process-callback

Also, check out intersects and overlap if you don't need the cars to actually 'bump' into each other, but to just detect if they are touching. They are a bit faster than collide.

https://phaser.io/examples/v2/arcade-physics/direct-body-movement

http://phaser.io/docs/2.6.2/Phaser.Physics.Arcade.html#intersects

http://phaser.io/docs/2.6.2/Phaser.Physics.Arcade.html#overlap

Link to comment
Share on other sites

7 hours ago, Arcanorum said:

It sounds like you want to check which car is moving when a collision happens, as if only one car can be moving at once. You will just need to check the velocity of each car when the callback is called. If one of the cars has a velocity in either x or y that is not 0, then that car is the one that is moving, so remove that car, or the other car.

I think this will do..

Thanks for everything

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...