- Home /
(2D) How to maintain perfect elastic collisions?
Hey all! I am trying to make circles have perfect elastic collisions with each other. Instead of having perfect elastic collisions, they slow down over time and tend to hug the border.
Here is a description of my project: multiple circular prefabs are instantiated at runtime with random velocities in random directions. There is a circular border surrounding these prefabs. All circle prefabs have Rigidbody 2D (no gravity), and Circle Collider 2D (with a physics material set to 0 friction and 1 bounciness). The circular border is just a circular Edge Collider 2D with the same physics material as the circle prefabs.
Is there anything I'm missing?
Answer by tanz94 · Dec 28, 2014 at 06:20 AM
One can record the velocity before collision that can be done through raycasting(OnCollisonEnter would be of no help sine it records zero velocity).Also you have compute the normal and tangent and take dot product with initial velocity to get the velocity after collision.Follow these vidoes (https://www.youtube.com/channel/UCa0KlT6mWPvUdk-48kFaSUg/videos ) for better understanding.Soon a blog will be written on it.
Answer by Kiwasi · Dec 28, 2014 at 08:16 AM
Record the total initial momentum of the system. In each collision check the the total amount of momentum, and adjust as appropriate.
Unity will remain pretty good elasticity, but due to floating point precision errors and rounding errors the system will eventually break down.
Your answer
Follow this Question
Related Questions
Ball slows down like crazy out of nowhere! 0 Answers
How to stop projectile collider (is trigger) from colliding with other colliders (also is trigger) 2 Answers
How to tell if my character hit a collider of a certain layer 1 Answer
The tilemap collider is simply not working 0 Answers
How to use OverlapCollider? 1 Answer