- Home /
Collision.impulse 2D equivalent
For 3D collisions you have Collision.impulse. Is there an equivalent (or a way to get an equivalent value) for 2D collisions?
Answer by samifruit514 · Jun 28, 2016 at 11:56 AM
you can calculate the bodies velocity magnitude over a couple of frames like in this thread: http://forum.unity3d.com/threads/getting-impact-force-not-just-velocity.23746/
look at Nutella's post
Answer by RodrigoSeVeN · Nov 01, 2017 at 10:38 PM
I'm migrating my game's physics from 3D to 2D and have just faced this same problem. After a lot of searching and testing a few methods, including the one on the previous answer, I couldn't get anywhere near the same results from Collision.impulse.
Finally, the most ok method I found, which has a lot of room for improvement, was to simply use Collision2D.OverlapPoint to check in a loop each point in the contacts array of the OnCollisionStay2D collision parameter, to see if any of the points were inside my object as such:
if (collision.otherCollider.OverlapPoint(contact.point)) {}
Since I was using impulse to check if my object was being crushed, this method has been working well enough to replace it. It doesn't give you a nice number to work with, so it might not be what you needed. I thought it was better to share anyways, in case someone else is trying to crush a 2D physics object.
For those trying to crush an object, you might want to change the crushed object's layer so it doesn't collide with whatever crushed it any longer than necessary. It really depends on what you're trying to achieve.