Hello! So I have a problem where when rotating a Transform on two axes simultaneously causes the third axes to be rotated also.
public class RotationManager : MonoBehaviour
{
private Quaternion _targetRot;
public RangeFloat xClamp = new RangeFloat(-360f, 360f);
public RangeFloat yClamp = new RangeFloat(-360f, 360f);
public RangeFloat zClamp = new RangeFloat(-360f, 360f);
private void Start()
{
_targetRot = transform.localRotation;
}
private void Update()
{
transform.localRotation = _targetRot;
}
public void AddEulerAngles(Vector3 vector)
{
_targetRot *= Quaternion.Euler(vector);
}
public void AddQuaternion(Quaternion quaternion)
{
_targetRot = quaternion * _targetRot;
}
and
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GunRecoil : MonoBehaviour
{
public RotationManager rotationManager;
public float xRecoil = 5f;
public float yRecoil = 1f;
void Update()
{
if (Input.GetButtonDown("PrimaryAction"))
{
rotationManager.AddEulerAngles(new Vector3(yRecoil, xRecoil, 0));
}
}
}
Maybe my approach isn’t correct? I am trying to make a system where you can have the mouse look and the recoil affect the rotation of the camera. In all the examples and tutorials, using their approach, one script would override the rotation of another. The mouse look script (not attached) works as intended. As does the recoil. But when I try to rotate two axes at once, it will rotate the third. In this case the Z axis.
Any help would be appreciated. Thanks