- Home /
Input axis' switching unintentionally.
I am setting up a control script for a ship. I have everything working how i want but have one issue. So i have 3 axis' yaw, pitch and roll. The roll always stays the same as intended. The issue is with the pitch and yaw. When i turn the ship 90 degrees up or down(pitch), the yaw and pitch inputs switch.
I have the troubled axis' mapped to the right stick on an xbox one controller. So for example: Right stick up and down controls pitch and right/left controls yaw. If i pitch the ship up 90 degrees those inputs switch. UP/Down becomes yaw and Left/right becomes pitch.
Can anyone give me me an explanation why this is happening and a possible fix. Thanks very much in advance. Here is the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float Speed = 200.0f;
public float RollSpeed = 200.0f;
public float PitchSpeed = 200.0f;
public float YawSpeed = 200.0f;
public float smooth = 3.5f;
public Rigidbody rb;
float roll = 0;
float pitch = 0;
float yaw = 0;
float vertical = 0;
float horizontal = 0;
float thrust = 0;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
Move();
}
public void Move()
{
Quaternion AddRot = Quaternion.identity;
roll += Input.GetAxis("Roll") * (Time.deltaTime * RollSpeed);
pitch += Input.GetAxis ("Pitch") * (Time.deltaTime * PitchSpeed);
yaw += Input.GetAxis("Yaw") * (Time.deltaTime * YawSpeed);
vertical = Input.GetAxis ("Vertical") * (Time.deltaTime * Speed);
horizontal = Input.GetAxis ("Horizontal") * (Time.deltaTime * Speed);
thrust = Input.GetAxis ("Thrust") * (Time.deltaTime * Speed);
AddRot.eulerAngles = new Vector3(-pitch, yaw, -roll);
AddRot = Quaternion.Euler (-pitch, yaw, -roll);
rb.rotation = Quaternion.Slerp (rb.rotation, AddRot, Time.deltaTime * smooth);
Vector3 AddPos = new Vector3(horizontal,vertical,thrust);
AddPos = rb.rotation * AddPos;
rb.AddForce(AddPos * Speed);
}
}
After more troubleshooting. I believe that the problem is not the axis' switching. It seems im only rotating along the global axis and not local to the game object. Ive tried transform.localrotation but that didnt do the trick either.
Your answer
Follow this Question
Related Questions
Touch to turn wheelcolllider.steerAngle with limits 1 Answer
2D Input.GetAxis not recognized when local scale is flipped 0 Answers
Simulate keyboard buttons to use Input.GetAxis ("Horizontal") 2 Answers
GameController Unity wrong Axis-Values 0 Answers
How Do I Snap Input Between 1, 0, and -1 0 Answers