Hi, How can i rotate a rigidbody around an arbitrary point instead around itself by applying a force on it? inertiaTensor can help? Thanks in advance -frens
So it may be a little late to help your problem specifically, but if anyone else comes by this question: Using RigidBody.MovePosition, RigidBody.MoveRotation, and the mysterious yet surprisingly helpful Quaternion, this can be achieved relatively easily:
public void rotateRigidBodyAroundPointBy(Rigidbody rb, Vector3 origin, Vector3 axis, float angle)
{
Quaternion q = Quaternion.AngleAxis(angle, axis);
rb.MovePosition(q * (rb.transform.position - origin) + origin);
rb.MoveRotation(rb.transform.rotation * q);
}
- Build a
Quaternion
using the provided angle, and the axis around which we would like to rotate - Translate the point back to the origin (point around which we are rotating) multiply it by the quaternion to rotate it around the desired axis, translate it back, and use the resulting point as a target for
Rigidbody.MovePosition
- Set the object’s rotation with
Rigidbody.MoveRotation
by multiplying the current rotation by the new (multiplication is like addition for quaternions, I couldn’t tell you why).
Here are a few suggestions:
- Use the animation system
- Attach a joint to the rigidbody and anchor it at the pivot point
- Change the rigidbody's center of mass
It is cause the it will rotate around its anchor point so try to move the anchor point the the place you need it. hope that helped