LookAt problem

Im making a scipt that will allign turrent to nearest target but i have a problem: it alligns the turret on wrong axis. I want X axis as “front” of turret bt it uses top as front and it faces its top towards the target. How do I fix it?

I guess that the axis are assigned the wrong way on your model. Either you fix it in your 3D program or you make the turret a child of an empty gameObject and then you call lookAt for the gameObject. That way you can adjust the local Rotation of your turret.

Or did you mean to only rotate it on one axis?

in that case you could use something like this:

var turret : Transform;

function Start()

var turretRotation : Vector3 = turret.rotation;
turret.LooktAt(target);
turret.rotation.x = turretRotation.x;
turret.rotation.y = turretRotation.y;

this script would rotate the turret only on it’s z axis