# Setting rotation Angle / rotation question

Hello,

can I set objects rotation angle (vs rotating it by some degree?) say set angle 90, (on local axis)

## long version

I have Cylinder with 6 sides, some object is moving on a path through this cylinder. this object is at the center of the cylinder all times, another object is attached to it and is some distance away from this object.

sorry for the crappy pic (: did it in paint

I want to rotate it left 60 degrees when A is hit, and rotate right 60 degrees when I hit D. basically its like sides of cylinder are racing tracks, and with each rotation player is moved(rotated) to the center of next side.

I'm using this script

``````var rotation = 0;

function Update () {
//rotate player when Ais hit
if (Input.GetKeyDown ("a")) {
// rotation += 0.2;
transform.Rotate (rotation,0,0);
}
if (Input.GetKeyDown ("d")) {
// rotation += 0.2
transform.Rotate (rotation*-1,0,0);
}
}

``````

and I get some weird result like 29.9, 30.1 rotations when default rotation of null is 90 O_O so I figured if I have array with each possible angle in it, and I directly set angle of object to some degrees I will avoid this weird angles. but how do I do that?

How are you moving your null object along the centre line of the tube?

Are you also aligning your object with the direction of the tube's path?

What you should be doing, each Update() is this:

1) Set your null object to the new position along the path

2) Set your null object's rotation so that it is aligned with the path direction. For example:

``````nullObject.transform.rotation = Quaternion.LookRotation( pathDirection );

``````

3) Now rotate the null object around its own local forward axis by the full amount (because the previous command will have reset the rotation entirely):

``````nullObject.Rotate(Vector3.forward * playerAngle);

``````

So, when put together, your Update() function might look something like this:

``````float playerAngle = 0;
float turnSpeed = 30;

void Update() {

playerAngle += Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;

transform.position = GetPathPosition();
Vector3 pathDirection = GetPathDirection();
nullObject.transform.rotation = Quaternion.LookRotation( pathDirection );
nullObject.transform.Rotate(Vector3.forward * playerAngle);

}

``````