# rotate gameobject

i have 2 gameobject “TanHead” and plane(with position increment in x ) ,what i want is my TanHead to follow plane with only rotation ,position of Tank is fixed .so when my gameobject (plane) is above Tank the rotation on TanHead will be 270 degree. i have looked and tried lookat function but i cant use that because i want to fix tank rotation upto 0 to 90 degree

here is my my image [24308-start+.png|24308]

here is what it should look like when my plane goes by

now what m using for rotation

``````var target : Transform;
var myself:Transform;

var tempAngle:float;

private var angle: Vector3 = new Vector3(360,270,0);

function LateUpdate()
{
myself.LookAt(target);
if(myself.transform.rotation.x != 0)
//seem to get a 0 if my target is in
//certain places because I am using a mouse pos and hit with plane.
{
tempAngle = myself.transform.rotation.x * 100; //don't know how to read a euler
//angle into a float so I just multiplied by 100 to get the angle.
}
else
{
tempAngle = tempAngle;
}
myself.rotation = Quaternion.Euler(tempAngle,270,0);

}
``````

what i can do to fix it because with this script when my plane goes to 270 degree it direct it self to 360 degree causing big jerk thank you

void Aim()
{
Vector3 direction = Vector3.Normalize(targetTransform.position - transform.position);
float angle = Mathf.Atan2 (direction.y, direction.x) * Mathf.Rad2Deg;
Quaternion rotation = Quaternion.AngleAxis(angle,Vector3.forward);
transform.localRotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime);
}

This is what I think you want. Attach it to the TanHead. You might need to change the Pivot point of your sprite to get the effect right. you find the direction you need to look and then use the Atan2 function to rotate to it in 2 Dimensions.

If you want the TanHead to follow the gameobject precisely then remove the Quaterion.Slerp() function and just set it to the rotation variable. you might also want to use Mathf.Clamp() on the angle but that is up to you.