2D Toolkit Forum
2D Toolkit => Support => Topic started by: JBabz on August 25, 2013, 03:43:45 am
-
This code should make the player rotate (he's on the XY plane) according to joystick movements.
Just straight up, what's wrong with this code? (not to be cliche or anything)
private void joystickMovementUpdate() {
direction = new Vector3(Input.GetAxis ("Right Joystick Horizontal"), Input.GetAxis ("Right Joystick Vertical"), 0);
horizontalAxis = Input.GetAxis ("Left Joystick Horizontal");
verticalAxis = Input.GetAxis ("Left Joystick Vertical");
if (direction.sqrMagnitude > 0.1f) {
qTo = Quaternion.LookRotation(direction);
qTo.eulerAngles = new Vector3(0, 180, qTo.eulerAngles.z);
}
transform.eulerAngles = new Vector3(0, 180, transform.eulerAngles.z);
transform.rotation = Quaternion.RotateTowards(transform.rotation, qTo, ROTATION_SPEED * Time.smoothDeltaTime);
move ();
}
-
This looks so complicated for what you're trying to do. Get it working with the atan2 code I posted a while ago, and then it should make a bit more sense how you should do it. If you can assign a value, you just rotate towards that Quaternion.Euler( ... ) instead.