Question by
SavvaMadar · Dec 10, 2017 at 08:25 AM ·
rotationrigidbodylocal
Rigidbody following a rotation in local space (SEMI WORKING CODE)
I found the following script to get a rigidbody to match the world rotation of a transform:
public Transform target;
private Rigidbody rb;
// Use this for initialization
void Start () {
rb = transform.GetComponent<Rigidbody>();
}
// Update is called once per frame
void FixedUpdate () {
rb.maxAngularVelocity = 1000f;
Quaternion rotation = target.rotation * Quaternion.Inverse(rb.rotation);
rb.AddTorque(rotation.x / Time.fixedDeltaTime, rotation.y / Time.fixedDeltaTime, rotation.z / Time.fixedDeltaTime, ForceMode.VelocityChange);
rb.angularVelocity = Vector3.zero;
}
But this rotation is applied to the rigidbody via world space. I can't figure out how to make it local.
Comment