- Home /
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?
Yes. But to the left would be the direction not on the gameobject axis but the viewers view also. It is tumbling so I have no static axis reference. Rotation would be something good to know also. The gameobject is tumbling randomnly.
Thanks.
Answer by aldonaletto · Sep 05, 2011 at 03:42 AM
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?
In respect to an object tumbling I am more concerned with the direction of travel and not the rotation. While an object is tumbling the axis directions are dynamic and rotating in numerous directions but the direction of travel is still a straight line. It is this straight line I am trying to maintain. While the parent is rotated the straight line of the child gets bent meaning the direction of travel is curved towards a global direction and not within the rotated parent:
http://www.youtube.com/watch?v=Vi4XTYREXv0
As can be seen by the YT the rotation of the parent (the box) causes a change in the force direction but when the box stops rotating the child (the sphere) continues in the original direction of the child and not the rotated direction of the parent. I hope this is clear. At this point the YT only shows the problem. This Unity project is for a physics demonstration of a confined space.
I include this link. I am not concerned with rotational velocity. http://en.wikipedia.org/wiki/Angular_velocity
You mentioned this: rigidbody.angular.velocity Did you mean rigidbody.angularvelocity. I could not find angular by itself with a dot product afterwards.
Your answer
Follow this Question
Related Questions
Error on 'velocity = [Vector3].normalized'? 1 Answer
Normalizing vector doesn't give a constant direction. 2 Answers
Can't access the velocity of a rigidbody: 'Rigidbody' does not contain a definition for 'velocity' 1 Answer
Animation or smooth teleportation 0 Answers
Is there a way to stop a rigidbody from moving in a specific direction? 1 Answer