• 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
Question by abstractfragment · Jan 21, 2015 at 03:40 AM · rotationvectorstransforms

Rotate a vector WITH transform.

Hello, I am working on a top down game in which the player is able to move in eight directions, forward, back, left, right and diagonals. The direction is established through vector3 and is a rigidbody force. This is controlled by WASD. I want the arrow keys to control the camera angle in 90 degree increments. However the vector3 stays the same, so that pressing up would move the character right according to the newly rotated camera. How would I go about rotating the vector?

Comment

People who like this

0 Show 12
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 Superrodan · Jan 21, 2015 at 03:49 AM 0
Share

Just a question to help me understand the scene. If you were to go into your scene, change the rotation of your camera to 90, then press start, would you get the control scheme you are looking for?

avatar image abstractfragment · Jan 21, 2015 at 03:51 AM 0
Share

No. Sorry, I forgot to elucidate that it's not EXACTLY top down, the camera looks down on the character at an angle. The camera is technically slightly behind and above the character.

avatar image Bunny83 · Jan 21, 2015 at 03:53 AM 0
Share

Your name fits your question perfectly. It's just an "abstract fragment"...

If it's a top down game it sounds extremly strange if you talk about changing "the angle". What angle? around which axis? Also what "vectors" do you actually talk about? How about showing the relevant code, a screenshot or a conceptual drawing of you problem?

avatar image abstractfragment · Jan 21, 2015 at 03:59 AM 0
Share

The character is being transformed, rotated. So that this alt text becomes this alt text.

Relelvent code fragment.

         if (Input.GetButtonDown("rotate"))
             {
             transform.Rotate(Vector3.up * (90 * angleAxis));
             }

Sorry for the confusion amigos. By top down I really mean 45 degree angle down.

1.png (78.4 kB)
2.png (89.6 kB)
avatar image Superrodan · Jan 21, 2015 at 07:51 PM 1
Share

Sure. You started a conversation with me on the forums. I think it would be best to continue this there so we don't keep bumping this question

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Superrodan · Jan 21, 2015 at 07:48 AM

What you want to do is use "transform.forward" in your code instead of Vector3.forward.

Vector3.forward is in world space and always goes in one direction based on world space. "transform.forward" goes forward in the gameObject's local space.

Comment
abstractfragment

People who like this

1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

Offset raycast by specific amount 1 Answer

How to rotate a quad 1 Answer

Make an object point to another which keeping its forward along an axis 0 Answers

Instantiating Platforms between two Vectors 1 Answer

Rotating tank barrel on X axis while the parent Turret rotates on Y axis 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