Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BigSquirmy · Jul 05, 2017 at 04:22 AM · quaternionsinput.getaxis

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);
     }
         
 }
 
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BigSquirmy · Jul 05, 2017 at 06:00 AM 0
Share

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.

avatar image Jwizard93 · Jul 05, 2017 at 10:44 PM 0
Share

Check this out.

link text

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges