- Home /
Rotation based on velocity on one axis
Hi there, I am currently trying to achieve a rotation to a 3D object on only on axis, this being the Z axis. Imagine this scenario, the player is shot out of a cannon, with a random speed based on some previous actions, I then need to player to rotate, based on the speed of which it is throw out the cannon, any help is much appreciated! Thanks (C# is prefeered, but UnityScript is also good :) )
you can able to get angle based on your velocity. I have used same thing in other engine Angle based on terrain
@siddhart3322 Thanks for the link, but it all seems quite confusing when it is in another engine. Does someone else know how to do this? :)
Answer by robertbu · Apr 18, 2014 at 09:39 PM
I think you are asking this:
float rotateSpeed = rigidbody.velocity.magnitude * factor;
transform.Rotate(0,0,rotateSpeed * Time.deltaTime);
'factor' is a variable you define that maps a velocity to degrees per second.
Thanks for this answer but what value I have to apply for factor? This variable confusing me. So please provide only that detail.
You will have to play with various values to get the behavior you want. I'd start with a velocity you consider maximum or if you don't have a maximum, consider very fast. Figure out how fast you want want to rotate (degrees per second) when the velocity is that fast. Rotation / $$anonymous$$axSpeed = factor. After playing you may decide that a linear factor is not good enough or that you want to max the rotation speed for velocities above some threshold. Either will involve more lines of code, but are doable.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Displaying the y value score,Displaying the score of the Y value 1 Answer
Orbit over 1 hour with acurate timer 1 Answer