• 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 mei_huang · Dec 18, 2020 at 04:26 AM · scripting beginnercharacter movementrotatetowards

rotating Character 90 degrees in relation to world and move in direction.

I am taking a unity class in school and i may have made my project a bit overly ambitious. Essentially I am taking an old 2D side scroller game and trying to make it in 3D. Therefore my character can move left and right. forward and backwards on platforms. But i need my characters to turn exactly 90degrees in Y (no inbetweens) to face the left and right and exactly 180 degrees to face back. I've tried transform.Rotate(0,90,0) and transform.Rotate(0,-90,0) but it doesn't take into account if my character has faced left twice (and now is facing back) and I now want it to face forwards. Is there a way of making sure that the character faces left side of the world when the it turns left and the right side of the world when it turns right. And the same for front and back. ( i am using the wasd keys to control the characters movements),

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by CmdrZin · Dec 18, 2020 at 09:11 AM

You could try setting up four Quaternion rotations and just set the transform.rotation to one of the four.
see https://docs.unity3d.com/ScriptReference/Transform-rotation.html

Comment
Add comment · Show 1 · 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 mei_huang · Dec 18, 2020 at 09:38 PM 0
Share

@CmdrZin wow...I felt really dumb. Thank you for pointing me in the right direction. I've been staring at the code for hours and i finally got it!

avatar image
0

Answer by mei_huang · Dec 18, 2020 at 12:39 PM

@CmdrZin Do you have an example of how you would set up for quaternion rotation? O_O I tried it using transform.rotation = Quaternion.Euler(transform.rotation.x, -90, transform.rotation.z) and so on for all the directions, and while my player rotates like i want them to, i know Quaternion messes with the numbers making it go all crazy and my player stops being able to move.

Comment
Add comment · Show 1 · 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 CmdrZin · Dec 18, 2020 at 06:14 PM 1
Share

No, but look at https://docs.unity3d.com/ScriptReference/Quaternion.html
for other possabilities and https://docs.unity3d.com/$$anonymous$$anual/QuaternionAndEulerRotationsInUnity.html

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

120 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

Related Questions

Character will not go from Ide to Walk 1 Answer

Rotate the character movement with the character 1 Answer

Rotating player with Quaternion and RotateTowards 1 Answer

The character controller stop moving when the Speed Start increase Endless runner 0 Answers

Cannt get a function to run only on Client 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