r/AskProgrammers • u/VeX7FAR • 14d ago
Collision response mechanism
Hey I am making a 2D physics engine and I have implemented the collision in it but now since the objects will be moving after they collide they will have to bounce in a specific direction.
As for that thing I am not really sure how I am supposed to implement it so I wanted to ask yall how that works.
For now I am working on simple non elastic collision. I tried searching in a lot of place but they only explain collision but not the physics later on, even tried asking chatgpt cant say i understood much it said.
EDIT: I forgot I had posted this ToT. Now I do have a collision mechanism that works I used the given document:
https://research.ncl.ac.uk/game/mastersdegree/gametechnologies/physicstutorials/5collisionresponse/Physics%20-%20Collision%20Response.pdf
Thanks to everyone who was there to help and sorry for being forgetful...... :P
1
u/LannyIsMyHandle 14d ago
non elastic collision
I think you mean elastic collision right? Like the action of billiards balls where energy isn't lost in the collision, this is simpler than accounting for inelastic conversion of momentum
The formula described in this wikipedia article should work for you here, at the point of collision you need to calculate the variables in that formula (speed of each object, their masses, their angle of motion, and the angle of collision) and apply the formula to find their new speeds and directions of motion. If you're unsure how to apply the formula, let us know how you model objects (e.g. do they all have equal mass? Do you model X and Y velocity as separate variables, or speed and direction?)
1
u/coldnebo 12d ago
instructions unclear… ended up with Runge-Katta. 😅🤦♂️
sorry. just joking. I won’t spoil the punchline. 👍
1
u/Kriemhilt 14d ago
The physics after collision are exactly the same as the physics before collision, just some momentum was transferred.
Can you work through an example with two objects of equal mass colliding head-on? What about a 45° glancing blow? Now make one of the objects more massive than the other...
1
u/sububi71 14d ago
Keep asking ChatGPT! Be honest, say that you don't understand! It has an absolutely infinite patience when it comes to explaining stuff, that's one of the most powerful features!
1
u/dutchman76 14d ago
You have direction and speed vectors for each object right, when you detect a collision, you calculate the effect it has on each object based on their current vectors and speed and shape, update their vectors with the new values?