Turret rotating on a z axis
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")":
https://www.youtube.com/watch?v=QKhn2kl9_8I&t=1347s.
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.
Please help me.
Thank's.
Answer by ownerfate · Jan 14, 2017 at 05:30 PM
I may know why it might not 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.
give it a shot.
hope that helped.
I asked this question because i'm making a 2d space shooter game. And i want to attach a turret to my spaceship that will see the nearest enemy and shoot at it.
Your answer
Follow this Question
Related Questions
3 Axis Camera Rotation 0 Answers
How can I clamp a target rotation within the rotation limits of a character joint? 0 Answers
Turret rotation based on its own local rotation. 3 Answers
Why does RotateTowards rotate in an "orbit" rather than on the spot? Help me understand! 0 Answers
Rotate an object to a position only through one axis 1 Answer