# Collision detected between 2 sprites, now what!?

This topic is 4988 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can detect collision between 2 sprites, but how do I figure out who slammed into who?? Sprite A hits Sprite B

##### Share on other sites
There are many ways of doing this. Here is the method that I would use:-

Check the directions that the sprites were moving in. If sprite X was moving away from sprite Y and there was a collision between them, then sprite Y would have slammed into sprite X.

##### Share on other sites
If you check for collisions within your movement code then the object you checked is the initiator of the collision.

##### Share on other sites
Well the collsion detection works by checking if the sprites are on top of eachother. It needs to be like this: If there is collsion check who slammed into who

##### Share on other sites
Most movement routines move the sprite to a NEW location and keep the OLD location, then check for collisions and only move if the there are no collisions. In this case (where you check for the NEW location collision) it is always the initiator of the move that caused the collision because at that point in time nothing else is moving.

How does your movement code work?

If you just move the position of the sprite and then check for collisions I'd suggest changing to the above method.

##### Share on other sites
Quote:
 Original post by D3DXVECTOR3Well the collsion detection works by checking if the sprites are on top of eachother. It needs to be like this: If there is collsion check who slammed into who

It depends on what you mean by "who slammed into who". What does it mean in terms of gameplay? (What difference does it make?) If it's for physics simulation, for example, to chenge the speeds, then you don't really need to know who bumped into whom, because you can just use the difference of the pre-bump speeds to calculate new velocities. If it's some other game mechanic, then I imagine the particulars would determine your testing procedure.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 9
• 34
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634122
• Total Posts
3015644
×