- Home /
rigidbody.angularVelocity Negative Value?
I have to know if it is possible to get a negative value if a rigidbody is spinning the opposite way?
I have a script that is reading the angular velocity of a propeller and adds a force according to that. But when I am spinning it in the opposite direction, it does not add a negative force.
 #pragma strict
 
 var CCWSpeed : float = -100;
 var CWSpeed : float = 100;
 var ForceModifier = 60.0;
 
 function Update () {
 var p = rigidbody.angularVelocity.magnitude / ForceModifier;
 rigidbody.AddForce(transform.up * -p );
 }
 
 function FixedUpdate () {
     if(PlayerInformation.playerCar == transform.parent.name){
         if(Input.GetKey(KeyCode.Mouse0))
             rigidbody.AddTorque(transform.up * CCWSpeed);
     
         if(Input.GetKey(KeyCode.Mouse1))
             rigidbody.AddTorque(transform.up * CWSpeed);
         
     }
 }
Answer by meat5000 · May 29, 2014 at 06:29 PM
The difference between speed and velocity is that velocity has a direction.
Using
rigidbody.angularVelocity.magnitude just uses a scalar. Its just the value component without the direction. Reverse the vector but the magnitude comes out positive as it involves taking squares, which removes -ve component.
So if you want to check whether the object is rotating clockwise or counterclockwise around the vertical axis, you can test the sign of Vector3.Dot(Vector3.up, rigidbody.angularVelocity)
Vector Dot returns a scalar, so will just give the angle. Test the direction by using cross product, which returns a vector. The z will show you the direction.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                