I have a plane as a player and I have two methods in my player controls class. The first one is working fine and it’s about moving horizontally and vertically. The second one is for having the player move a little bit on the sides when moving on the horizontal and vertical axis so the movements to not be so precise. But the moment I press play my plane is rotated to the other side (the x and y are changed). How can I fix this?
[SerializeField] float positionPitchFactor = -2f;
[SerializeField] float controlPitchFactor = -10f;
[SerializeField] float positionYawFactor = 2f;
[SerializeField] float controlRollFactor = -20f;
float xThrow, yThrow;
void Update()
{
ProcessTranslation();
ProcessRotation();
}
void ProcessRotation()
{
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
float pitch = pitchDueToPosition + pitchDueToControlThrow;
float yaw = transform.localPosition.x * positionYawFactor;
float roll = xThrow * controlRollFactor;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}