- Home /
Rotating around self axis by n degrees ??
Hi,
Like in the topic - how to rotate around self axis by a limited angle ? Quaternion.RotateTowards() does not handle this.
I can do endless rotation with transform.Rotate() but cannot find a way to limit this.
Eg.: At start I have a cube rotated by 45 degrees around Z axis. Then in play mode I want to do animated rotation around self Y axis by 90 degrees.
Is it that complicated or am I missing something ?? Please help.
Many thanks.
Answer by Hellium · Dec 04, 2017 at 04:37 PM
Try the following :
public float rotationSpeed = 20;
private float angle = 90;
protected void Update()
{
if ( angle > 0 )
{
float a = Mathf.Min( rotationSpeed * Time.deltaTime, angle );
angle -= a;
transform.Rotate( 0, a, 0 );
}
}
Works !
I have no clue why this is not built into the transform.Rotate() method. Will make an extention with options to rotate around any axis and set clockwise and counter clockwise directions.
Your answer
Follow this Question
Related Questions
Flying player Rotates in the left and right direction not forward and back 1 Answer
Having trouble rotating a turret 1 Answer
90 degree rotation script, cant find or make one that works for my needs. 1 Answer
I want to use LookAt but based on the object original rotation 1 Answer
Rotate a gameobject by a specific angle and stop when character doesnt move anymore 0 Answers