Hello all.
I’m trying to make a game. And i wan’t to know how can i make a turret rotate to the nearest enemy but on the z axis. I have made the same code like the tutorial on Brackeys about “Tower Defence (“Turrets”)”:
But at his code it say’s : Vector3 rotation = lookRotation.eulerAngles;
transform.rotation = Quaternion.Euler(0f, rotation.y, 0f);
So i replaced the “y” with a “z” like so : transform.rotation = Quaternion.Euler(0, rotation.z, 0); but it doesn’t work. I’ve tried switching them but it doesn’t work.
but there is my script for my character’s arm to rotate on the Z axis, you’ll have to do some fanegling, to get it to work.
code:
function LateUpdate ()// this is unchanged from my script.
{
rotationZ += Input.GetAxis("Mouse Y") * sensitivityZ;
rotationZ = Mathf.Clamp (rotationZ, minimumZ, maximumZ);
transform.localEulerAngles = new Vector3(0, transform.localEulerAngles.y,rotationZ);
}
judging by mine, while looking at yours, my script doesn’t use Quaternions, but this script has a clamp so it won’t do 360, but, removing the (Clamp) middle line of code, with the 2 lines left, will probably be what you’re looking for.
take what you need from this, and see what happens, and switch what you need to switch to make it work.