I have this script:
ball.transform.LookAt(ball.transform.position + ballvelocity);
ball.GetComponent.().AddRelativeTorque(Vector3(5000,0,0));
why the ball rotates on all axis?
I have this script:
ball.transform.LookAt(ball.transform.position + ballvelocity);
ball.GetComponent.().AddRelativeTorque(Vector3(5000,0,0));
why the ball rotates on all axis?
I wouldn’t expect any of that to work properly:
Perhaps you could consider decoupling mesh transform from physics?
function Start () {
ball.GetComponent.().maxAngularVelocity = 200;
ball.transform.LookAt(ball.transform.position + ballvelocity);
ball.GetComponent.().AddRelativeTorque(Vector3(5000,0,0));
}
I want that ball rotates on the direction of its velocity.
But this is in Start() so it is only executed once. Please use Code Tags.
This chart can help visualise issues:
I noticed that if ball rotation = (0,0,0) the relativetorque works correctly and rotates the ball on x axis. But when i change the ball rotation the relativetorque rotates the ball on all axis.
If i put a “Constant Force” element on the ball, the relativetorque works well even if the ball rotation is not = (0,0,0). So, how can i have the same result with the script? Thanks
Why it rotates the ball in all axis and not only on x axis? I should have (x,10,0) but it isn’t so. It’s so strange…
Ok, this is the key:
GetComponent<Rigidbody>().rotation = Quaternion.Euler (0,10,0);
I have transfom.rotation in my script, that’s why it doesn’t work. I have to rotate the rigidbody and not the transform before adding the force.
Rotations use Quaternions! You are trying o use Vector3 to do rotation. Follow the example that Eron82 shows.