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 /
  • Help Room /
avatar image
0
Question by Jimbobbedyjobob · Jan 06, 2016 at 12:20 PM · rotation3dvector3grideuler angles

Player Controls For Restricted Directional Movement, but those things vary...

So I am making a little game.

My camera is working pretty well now thanks to @Bunny83.

And having applied that same camera rotation code to my Playerobject, the player now continues moving in the same on-screen-direction even though the game-space has rotated by 90° in whichever direction.

Now, however, I am back to the problem of player control input.

I want the player to be able to use WSAD or similar 4-directional controls to move the player-object in the corresponding direction. Problem is that in worldspace, the true directions are reorienting all the time because the player-cam rotates around the play space.

I have tried using self-space rotation on the player object, tried various Vector.3 things.

I really don't want to have to end up using just two keys for Turn-90°-Left/Right, because that become difficult to interpret when the playerObject is not moving in a scree-vertical vector from bottom to top of the screen.

Any ideas, Oh Great Internets?

playerObject Code:

     public float currentSpeed;
 
     public float curRotX = 0f;
     public float curRotY = 90f;
     public float curRotZ = 0f;
 
     // Use this for initialization
     void Start ()
     {
 
     }
 
     // Update is called once per frame
     void Update ()
     {
         curRotX = gameObject.transform.rotation.x;
         curRotY = gameObject.transform.rotation.y;
         curRotZ = gameObject.transform.rotation.z;
 
         ForwardMotion ();
 
         RotatePlayer ();
         RotatePlane();
     }
 
     // to cause constant motion.
     void ForwardMotion ()
     {         
         transform.Translate (Vector3.forward * currentSpeed * Time.deltaTime, Space.Self);
     }
 
 
     // to rate the player gameObject
     void RotatePlayer ()
     {
         if (!(Input.GetKey (KeyCode.RightShift))) 
         {
             if (Input.GetKeyDown(KeyCode.W))
             {
                 transform.Rotate (curRotX, curRotY, curRotZ, Space.Self);
                 Debug.Log ("Player Turned North");
             }
             else if (Input.GetKeyDown(KeyCode.S))
             {
                 transform.Rotate (curRotX, curRotY + 180, curRotZ, Space.Self);
                 Debug.Log ("Player Turned South");
             }
             else if (Input.GetKeyDown(KeyCode.D))
             {
                 transform.Rotate (curRotX, curRotY + 90, curRotZ, Space.Self);
                 Debug.Log ("Player Turned East");
             }
             else if (Input.GetKeyDown(KeyCode.A))
             {
                 transform.Rotate (curRotX, curRotY -90, curRotZ, Space.Self);
                 Debug.Log ("Player Turned West");
             }
         }
     }
 
     // to rotate the plane of play
     void RotatePlane()
     {
         if (Input.GetKey(KeyCode.RightShift))
         {
             if (Input.GetKeyDown(KeyCode.W))
             {
                 gameObject.transform.Rotate(0f, 0f, 90f);
             }
             else if (Input.GetKeyDown(KeyCode.S))
             {
                 gameObject.transform.Rotate(0f, 0f, -90f);
             }
             else if (Input.GetKeyDown(KeyCode.D))
             {
                 gameObject.transform.Rotate(90f, 0f, 0f);
             }
             else if (Input.GetKeyDown(KeyCode.A))
             {
                 gameObject.transform.Rotate (-90f, 0f, 0f);
             }
             
         }
     }
 }

I have a screen capture video but UnityAnswers hates me and wont let me upload a 1.17MB MP4.

On the start plane it works just fine, I can WSAD my way to anywhere I want to go.

However, once I start rotating around the play-space, and thereby changing my plane-of-play, the controls become less useful, until I have to try to guesstimate how to use them and resort to just using my A & S keys, which are still often inverted due to my orientation.

Comment
Add comment
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

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

44 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

Related Questions

Rotate GameObject 90 degrees where is my flaw? 0 Answers

Using a directional vector to orient a sphere? 0 Answers

I want to make a script that causes the directional light to stop at 180 degrees. 0 Answers

Quaternion rotation issue please help :'( 0 Answers

Set transform.position relative to rotation 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