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 nussbau65 · Jan 04, 2018 at 12:42 AM · scripting problemmovementgamebeginner

How can I un-invert my first person spaceship controls in C#?

Hi, I'm trying to make a first person spaceship shooter game. I am currently working on the movement script and so far it has been going well, however I have it so that you can turn using Q and E. When this happens though it changes make controls and rotates the ships forward based on the global X-Y-Z axis rather than relative to it. Here is a sample of my code:

 public float forwardSpeed = 75f;
 public float lookSpeed = 75f;
 public float twistSpeed = 75f;

 private float pitch = 0;
 private float yaw = 0;
 private float twist = 0;
 private GameObject referencePoint;

 private void Start()
 {
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible = false;
     referencePoint = GameObject.Find("ReferencePoint");
 }

 void FixedUpdate ()
 {
     if (Input.GetKey(KeyCode.Q))
     {
         twist += twistSpeed * Time.fixedDeltaTime;
     }

     if (Input.GetKey(KeyCode.E))
     {
         twist -= twistSpeed * Time.fixedDeltaTime;
     }


     pitch -= Input.GetAxis("Mouse Y") * lookSpeed * Time.fixedDeltaTime;

     yaw += Input.GetAxis("Mouse X") * lookSpeed * Time.fixedDeltaTime;


     transform.eulerAngles = new Vector3(pitch, yaw, twist);

     transform.position += transform.forward * forwardSpeed * Time.fixedDeltaTime;
 }

I've been working on this for a while now and haven't been able to get it to work. I'm still pretty new to C# and Unity in general. Thanks in advance for any help I might get :),

Comment
Add comment · Show 1
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 David_Rios · Jan 04, 2018 at 12:52 AM 0
Share

Is your issue the fact that your controls are inverted or that the controls aren't working relative to your ship's rotation/position?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by moodymagyar · Jan 04, 2018 at 01:05 AM

@nussbau65 I don't know, instead of transform.eulerAngles have you tried transform.Rotate instead ? If you don't specify, the rotation should be around Space.Self instead of Space.World, which, if I am understanding your question, that is what's happening right?

Comment
Add comment · Show 2 · Share
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 nussbau65 · Jan 04, 2018 at 03:08 AM 0
Share

Awesome, thank you so much. It works great now

avatar image BhargavChauhan · Jan 04, 2018 at 06:32 AM 0
Share

@nussbau65. How do you solve this problem. can u post a code here.? I am facing the same problem.

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

189 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 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 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

I really need a JumpPad script for a JumpPad in unity 2D 0 Answers

How to restrict first person from turning 360 degrees when sitting? 1 Answer

I Have made a movement script for my pacman sprite. But animations keep playing even when there is no input. ans when i drag my sprite around in the scene it keeps trying to return to its original position. 0 Answers

How do you force the player to look forward/toward an object? 0 Answers

NPC movement 1 Answer


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