So i have a Tower Defense game that im making, and im attaching my towers to a sphere wich is the game level. But the tower is deformed when an enemy comes in range and it rotates towards it.
void Update ()
{
if (target) {
aim_pan.LookAt (target);
aim_pan.eulerAngles = new Vector3 (0, aim_pan.localEulerAngles.y, 0);
aim_tilt.LookAt (target);
pivot_pan.rotation = Quaternion.Lerp (pivot_pan.rotation, aim_pan.rotation, Time.deltaTime * turnSpeed);
pivot_tilt.rotation = Quaternion.Lerp (pivot_tilt.rotation, aim_tilt.rotation, Time.deltaTime * turnSpeed);
if (Time.time >= nextFireTime) {
FireProjectile ();
}
}
}
this is what rotates the tower, when i first place it its rotation is correct. aim_pan and aim_tilt are child objects. The base that rotates arount the y and the top that tilts up and down
GameObject newStructure = Instantiate (allStructures [structureIndex],
lastHitObject.transform.position, lastHitObject.transform.parent.rotation) as GameObject;
this is the instantiation of the tower, lastHitObject is a child plane to the sphere world. its rotated correctly aswell.