Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

collision reactions

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

If you intended to correct an error in the post then please contact us.

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 this post


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


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


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!