collision reactions
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.
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?
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...
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...
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement