- Home /
Question by
vCADv · Apr 14, 2020 at 10:50 AM ·
rotationinputquaternions
Add 180 quickturn to movement.
I have a very simple script controlling the objects rotation, I wish to add a quick turn button which adds a 180 degree turn to the y axis. What i have at the moment works in so far as the 180 degree turn is applied but snaps back to its original position instead of becoming the new orientation.
My apologies, I'm sure this is an obvious answer but i am new to Unity and everything i have tried has been to no avail.
{
[SerializeField]
float _rotationY = 0.0f;
float _rotationX = 0.0f;
public GameObject Player;
public GameObject DriftTarget;
private const float _distanceThresh = 0.05f;
private Quaternion _inputRotation;
private void FixedUpdate()
{
#region Player Input
//mouse control
_rotationY -= Input.GetAxis("Mouse Y");
_rotationX += Input.GetAxis("Mouse X");
_rotationY = Mathf.Clamp(_rotationY, -80.0f, 50.0f);
_inputRotation = Quaternion.Euler(_rotationY, _rotationX, 0.0f);
transform.rotation = _inputRotation;
if (Input.GetKey(KeyCode.Q))
{
var Rotation = transform.rotation.eulerAngles;
Rotation = new Vector3(Rotation.x, Rotation.y + 180, Rotation.z);
transform.rotation = Quaternion.Euler(Rotation);
}
#endregion
}
Comment
Answer by JackhammerGaming · Apr 14, 2020 at 10:57 AM
@vCADv there is way simpler method to rotate on a key press here it is
void Update(){ if (Input.GetKey(KeyCode.Q)){ transform.Rotate(0,180,0); } }
yea it's that short :-).
Your answer
![](https://koobas.hobune.stream/wayback/20220612231401im_/https://answers.unity.com/themes/thub/images/avi.jpg)