Horizonicblue Posted February 12, 2017 Share Posted February 12, 2017 Hi, Is there a way to check collision of only one sprite with other? game.physics.arcade.collide(sprite1,sprite2,callback); the above thing checks for collision by sprite1 to sprite2 and also sprite2 to sprite1. I want only one way check....has anyone done anything like this? Link to comment Share on other sites More sharing options...
Arcanorum Posted February 12, 2017 Share Posted February 12, 2017 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? Link to comment Share on other sites More sharing options...
Horizonicblue Posted February 13, 2017 Author Share Posted February 13, 2017 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 More sharing options...
Arcanorum Posted February 13, 2017 Share Posted February 13, 2017 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 More sharing options...
Horizonicblue Posted February 13, 2017 Author Share Posted February 13, 2017 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 More sharing options...
Recommended Posts