- Home /
Commands affecting rotation not working
Evening, guys.
Currently, I'm attempting to make it so that if the player has an enemy targeted, they'll automatically turn in their direction when attacking.
To achieve this, I've got a gameobject (called targetLooker) that follows them, and looks at the current target via transform.LookAt, and this is working just fine. The second piece is a line in the basic movement script that should make the player character's Y rotation equal that of the targetLooker's if they're targeting an enemy and attacking:
if(PlayerPos.hasTarget && isAttacking || isSkill)
transform.eulerAngles = Vector3(0, -targetLooker.rotation.y, 0);
This is working, but not as it should be. Instead, the player character's Y rotation only kind of equals the targetLooker's. Say, for example, that the player character is facing away from the current target, and the targetLooker is facing them nicely. If I attack, the player only turns halfway toward their supposed direction, and is facing to the left of the target instead.
Any idea what's wrong? In addition to eulerAngles I've tried Quaternion, Rotate, and rotation, but those aren't working either.
Ah, that's the ticket! Thank you my friend. Wanna put that as an answer?
Answer by Eric5h5 · Jan 26, 2012 at 04:52 AM
transform.rotation is a 4-dimensional quaternion, and rotation.y isn't the y axis. You want eulerAngles rather than rotation. Anyway you probably want to use LookAt rather than trying to directly set angles.
Your answer
Follow this Question
Related Questions
How to rotate transform only on its Y axis? 1 Answer
Camera viewport transformation from one world to the rotated world. 1 Answer
How to go from eulerAngle axis 270 to 0 by rotating 90 degrees? 1 Answer
Increment Car Rotation along with steering Wheel 0 Answers
How to get Angle float of specific axis.(Turret clamping related). 2 Answers