rigidbody.velocity.normalized application

How do I apply the var returned from rigidbody.velocity.normalized to the rigidbody in fixedupdate() to keep the gameobject of the rigidbody moving in the original tumble direction?

I can not use .forward because tumbling is momentum based and not axis based.

Do you want to apply a velocity in the direction the rigidbody is rotating? If the object falls to the left, for instance, you want it to move in that direction too?

–

1 Answer

1

You can have a vector indicating the horizontal direction it’s rotating or tumbling by calculating the cross product of rigidbody.angular.velocity and Vector3.up (the cross product of two vectors is perpendicular to both):

function FixedUpdate(){
  // create a normalized vector in the rotation direction
  var moveDir = Vector3.Cross(rigidbody.angular.velocity, Vector3.up).normalized;
  rigidbody.AddForce(moveDir * force);
}

Is this exactly what you want?