- Home /
Rotate object based on projectile impact
I am working with a 2D project, I have a bar that has a RigidBody2D attached and is locked in place but can still rotate on the z axis. I also have some 2D missiles that can be shot at it, and I want the bar to rotate when the missiles come in contact with it and explode.
I have tried RigidBody.AddTorque but I cannot figure out how to calculate which direction it should spin and how much it should spin, based on where the missiles impact it (for instance if the missiles hit the left side from the bottom, it should spin clockwise and if it hits closer to the center pivot, it should spin less than if it hit the very outside)
I would greatly appreciate any help, thanks.
The phisics engine should handle this for you if both objects have Rigidbody2D.
I want the rotation to be from the explosion, the missiles aren't moving very fast, it wouldn't rotate it enough.