According to the documentation the function referenced in the title should rotate a certain number of degrees around the specified axis. In the script below, however, the function is setting the rotation of the object to the specified number of degrees. Meaning, it rotates once and never again. Can anyone advise me how to modify this script so that the angle is updated each time the button is pressed? Just to make things clear, I'm using the asset "ReWired", which is an advanced input manager. So, on line 31, what you're seeing is a function that rotates the map clockwise when the Right Trigger on a gamepad is pressed, and counter-clockwise when the Left Trigger is pressed. Code (csharp): using UnityEngine; using Rewired; public class BattleMapControls : MonoBehaviour { public int PlayerID = 0; public float RotationAngle = 90f; public float RotationDeadzone = 0.1f; private Player _player; private Transform _battleMap; private Vector3 _rotateVector; void Awake () { _player = ReInput.players.GetPlayer(PlayerID); _battleMap = gameObject.GetComponent<Transform>(); } void Update () { GetInput(); ProcessInput(); } private void GetInput() { // Action ID = BattleMapControl/RotateMap _rotateVector.y = _player.GetAxisRaw(0); } private void ProcessInput() { if (_rotateVector.y > RotationDeadzone || _rotateVector.y < -RotationDeadzone) { _battleMap.rotation = Quaternion.AngleAxis(RotationAngle, Vector3.up); } } }
Your code is creating the Quaternion each time you update the rotation, hence your rotation will be the same. What you can do is multiply the rotation by the result of Quaternion.AngleAxis to rotate it (quaternions get multiplied together to "add" the result of their rotations). Alternatively the easier approach is to use Transform.Rotate instead: Code (CSharp): _battleMap.Rotate(Vector3.up, RotationAngle); This removes the need to worry about Quaternion math entirely and just makes your code a bit more readable.