I’m building a 2d game with airplanes, using the 2d-toolkit. I’m trying make and AI plane which would follow the player by rotating and moving towards him (I want it to only rotate on the Z axis), I’m using:
var deltaRotation = target.position - transform.position;
var rotation = Quaternion.LookRotation(deltaRotation);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 3);
to rotate the plane: and this, to move it:
var direction: Vector3 = Vector3(speed, 0.0, 0.0);
transform.Translate(direction);
but the plane only rotates around the player using the X and Y axis, if the player move down/up it doesn’t rotate on the Z axis.
And if I try to restrict the rotation to the Z axis by:
deltaRotation.y = 0;
deltaRotation.x = 0;
it doesn’t rotate at all.