- Home /
Collision detection problem
For a Physics project, I am trying to make a simulation which calculates the result of 2D collisions and shows them in real time. For the sake of the project, I am doing nearly all of the math in the code. My current setup is that each object in the system is a circle tagged "Puck" with a CircleCollider2D (set to trigger) and a Rigidbody2D. My issue is in calculating the result of the collision.
Things I have tried:
Using a method in a script attached to each object which calculates the resultant velocity of its own object. Problem: The engine calculates the first velocity, but then uses that resultant velocity to calculate the other velocity, so second object's velocity is incorrect
Keeping the velocity for calculations equal to the initial velocity for .05s, then overriding it with the resultant velocity. Problem: Unclean, and creates other problems when multiple collisions happen quickly
Finding when collisions happen mathematically in a manager script by comparing distances between two objects to the sum of their radii for all possible collisions. Problem: Just didn't work, had to create a buffer in the comparison because the distance was almost never exactly equal to the sum of the radii when calculating every frame, buffer created other problems
If anyone has any suggestions, perhaps about finding when two trigger objects collide in a manager script not attached to the objects themselves, that would be really helpful. Thanks!
Could you show us some of the code? To be more specific, the declaration of the resultant velocity, and all the uses of velocity in your math, and Unity's $$anonymous$$onoBehaviour methods you are using (Update and it's variants, OnTrigger..., etc)