Public Group

# collision reactions

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

## Recommended Posts

ok im doing a box bounding collision detection and i need to have it so that when one sprite hits another one it will bounce off my velocity and positions are stored as points though so you cant just subtract or call the invers of the x or y value and the thing your colliding with can be hit from any angle so i was just wondering how you would code this thx. if i wasnt clear enough let me know.

##### Share on other sites
You weren't clear.

##### Share on other sites
how did i know that was going to be my first post
whats not clear?

##### Share on other sites
are you asking what about what should happen after the collision takes place -- i.e. how specifically to determine the new velocity of each vehicle?

##### Share on other sites
yeah thats exactly it

##### Share on other sites
The most realistic way is to use an elastic collision:

Combined momentum of objects is constant before and after collsion:

m1v1 + m2v2 is constant,

where m1 and m2 represent the masses of the respective objects,
v1 and v2 their velocities.

Combined kinetic energy of objects is constant before and after collision:

Ek = ½mv2

Ergo:

½m1v12 + ½m2v22 is constant

Using these formuale (or a derivative of them) will produce the best, most realistic collisions. If you don't understand any of the italicised words, google them, or don't use this approach - it involves physical mechanics.

Next time, [google] or gd search before posting - this has been answered many a time before. If you still can't figure it out, you should look back at these resources before posting again, and you should always sit down and experiment with your problem until you find an adequate solution. Having people hold your hand as you program is no way to learn.

Regardless, best of luck in your endeavours.

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

##### Share on other sites
if you're trying to do something simple, you might want to determine the straight line along which each vechicle is travelling, and then swaping the sign on the slope and using the new equation to determine the next point.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 12
• 10
• 9
• 15
• 22