Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Tyler 2 · Nov 08, 2010 at 07:50 AM · rotationmovement

Rotation that is dependent on button presses?

I have an object that moves using WASD along the ZX plane(the camera is overhead). When It moves in any direction, its rotation stays the same(it just moves along the plane), how can I make it so that when I press W it faces one direction, D is another, etc.? Thanks

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 Proclyon · Nov 08, 2010 at 11:38 AM

you have to change the current rotation of the object stored in the transform.

Changing the rotation of the Y axis of the object is probably what you want.

Y + 90 = Face 90 degrees to right. Y +180 = Face 180 degrees to right. etc.

You can also use negative values if you want , so Y - 90 is face left

Be carefull as this is an ABSOLUTE Value, if your camera rotates along side the camera or your character is not aligned to an original position and lives in a turning world. If one of these does apply you will need RELATIVE positions.

To do that get the Camera.main.transform and extract from the camera transform the current rotation or the Vector information. Use that as , like this example possibly*BELOW*, to get the Relative information to always face the correct side.

Quaternion camRotation = Camera.main.rotation;
Quaternion myRotation = camRotation + /*myFacingDirection*/;
transform.rotation = myRotation;

If you change the rotation to match that of the camera + an addition of whatever you want you should be able to tweak a proper relative direction without to much effort. Just remember that the rotation is a Quaternion and you may need to be carefull when editing those. Just copy all the values you don't want to change and set the Y rotation value to per direction in a variable

Quaternion relativeLeft = new Quaternion(camRotation.x, camRotation.y - 1, camRotation.z, camRotation.w);

for right just use + 1 and so forth.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

(sprite2D) Movement like this game... 1 Answer

Rotation and movement applied to other objects 2 Answers

Character rotation help needed. 1 Answer

Quaternion.FromToRotation misunderstanding 2 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