Sign in to follow this  
Horizonicblue

Collision check for one sprite

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.