Hello,
Say I have two rectangular boxes in a Unity scene. They are both rigidbodies and have colliders. If I take one of these boxes and hit the other box near it’s rear end, the front will rotate towards the hit to compensate.
My question is: how one could go about registering the force, direction, and position of this hit, and converting this rotation into a translation?
Ie. If I were to hit the box near it’s rear end, I would like the hit box to be pushed off in the opposite direction, but by an amount still proportional to the force. Ideally, I’d have access to this force before it were applied, so that I could increase or decrease it by a given factor.
Thanks,
Juanelo
Hello, just to not leave the question unanswered for any of the curious in the future:
For this particular instance, (to get the specific effect I wanted) it was enough to activate the “Freeze Rotation” constraint for the appropriate axis in the Rigidbody settings in the inspector.
I guess technically speaking, while it fulfills my needs at the moment, it doesn’t truly answer the question.
While this isn’t urgent for me anymore, it still seems like an interesting question — how to convert a rotation force into a translation force – maybe there’s a simple, physics based answer?
Best regards,
-Juanelo
Well you essentially answered your own question by posing it.
You have access in the returned collision information to both the contact point and the contact normal. You have access to the angular velocity through the rigidbody itself.
The trick would be to cache the information from the collision, then when the angular velocity changes in FixedUpdate() perform your calculations on the velocity vector while zeroing out the angular velocity.
Hi Quetus,
I’ve recently come back to this.
I hit a snag because I can only seem to access the collision info when there is a collision — The problem is that if I allow the collisions to occur, they automatically apply their own forces to my objects. Is there any way to ignore collisions but still retrieve the collision info?
Triggers don’t seem to work, as they don’t return return information like the collision velocity or contact points.
Any ideas?