Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Kyle13524 · Jul 23, 2015 at 04:14 AM · rotationvector3quaternionforwardeuler

Vector3.forward only moves me in 2 directions when rotating

So the way I am creating my character controller is very different from most mmorpg games. Part of the idea came from Outspark's Fiesta Online, where wasd all moved the character at a degree offset to the camera. For example running with W would move you forward at 0 degrees from the camera while running with D would move you forward at 90 degrees from the camera. This was really nice because you can run towards yourself and easily see all angles of you're character, along with being able to turn with the right mouse button.

For a better idea, this is how I worked it out in code:

         float cameraY = cameraController.transform.eulerAngles.y;
         float transformY = transform.eulerAngles.y;
         
         if (Input.GetKey("w"))
         {
             if (transformY != cameraY)
             { 
                 transform.eulerAngles = new Vector3(0, cameraY, 0);                
                 playerController.SimpleMove(movementSpeed * transform.TransformDirection(Vector3.forward) * Input.GetAxis("Vertical"));
             }  
         }
 
         if (Input.GetKey("d"))
         {
             if (transformY != cameraY + 90)
             {
                 transform.eulerAngles = new Vector3(0, cameraY + 90, 0);
                 playerController.SimpleMove(movementSpeed * transform.TransformDirection(Vector3.forward) * Input.GetAxis("Horizontal"));
             }
         }
 
         if (Input.GetKey("s"))
         {
             if (transformY != cameraY + 180)
             {
                 transform.eulerAngles = new Vector3(0, cameraY + 180, 0);
                 playerController.SimpleMove(movementSpeed * transform.TransformDirection(Vector3.forward) * Input.GetAxis("Vertical"));
             }
         }
 
         if (Input.GetKey("a"))
         {
             if (transformY != cameraY + 270)
             {
                 transform.eulerAngles = new Vector3(0, cameraY + 270, 0);
                 playerController.SimpleMove(movementSpeed * transform.TransformDirection(Vector3.forward) * Input.GetAxis("Horizontal"));
             }
         }

This works pretty well in the sense that the player stays at an offset to the camera, and that all works great. But for some reason it only moves me in 2 directions. When I press W it moves me forward, but when I press S it still moves me in the same direction. Same with D and A.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Veldars · Jul 23, 2015 at 06:13 AM

Hi,

I think this is because you rotate your player, you must go forward with the absolut value of "Input.GetAxis" (Mathf.Abs) because the direction will be define by "Vector3.forwarrd".

When you want to go back your forward is back but you multiply it by a negative nuber so your character go in the same direction than with "W"...

I hope this is clear...

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Quaternion.Euler rotations don't add up 0 Answers

Problem with rotation around axis 1 Answer

How can I multiply the rotation of a mirrored object? 1 Answer

How do you manually override mecanim's interpolation with rotations? 2 Answers

Unity Rotate Raycast on Quaternion 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