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
1
Question by enricogp · Jul 30, 2020 at 09:18 PM · rotationpositionlocaltransform.translateglobal

Why is it moving locally instead of globally?

Sorry if if local vs global coordinates were extensevely explained before in this forum, but I still have doubst about it. I'm very noob at Unity, however usually I don't come with problems with local vs global positions. Recently I saw a tutorial and, from my understanding, it was explaining that "Vector3.up" is a global position, which supossedly means it will always points towards the global definition of "up", while a local position (example: transform.up) will change depending on where the object is facing. The problem is that right now I'm tryind to do a "snake-like" kind of game, but when I use "Transform.Translate(vector3.up)" it actually moves the snake always to where it is pointing to (it's a 2d game) depending of where it is facing, which is what I would expect of a local position system. If I use "transform.up", however, the snake always goes the same way no matter where it is facing (and it goes down instead of up), which in my understanding is supossed to be the behaviour of using local coordinates. What am I understanding wrong?alt text

Note: the player starts rotated by -90 degrees in the z axis, not sure if/how this affects rotations

snake.png (64.2 kB)
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
4
Best Answer

Answer by unity_ek98vnTRplGj8Q · Jul 30, 2020 at 10:44 PM

You are correct in your understanding of local vs global coordinates. If you look at the Unity Manual for Transform.Translate, however, you will see that it takes an optional second parameter that corresponds to the "space" in which you want to move. If you do not supply this parameter, it defaults to Space.Self. In other words, it will take any vector you give it and transform it into local space. So if you give it Vector3.Up, it will be transformed into transform.up. To fix this, you could tell it to move in world coordinates (or in other words, to not transform any vector you give it) by doing something like transform.Translate(Vector3.up, Space.World);. Or you could take the more direct approach and modify the position directly like transform.position += Vector3.up;

Comment
Add comment · Show 2 · 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 enricogp · Jul 30, 2020 at 10:49 PM 0
Share

Thanks you for your answer. Do you know why "transform.Translate(transform.up)" doesn't work?

avatar image unity_ek98vnTRplGj8Q enricogp · Jul 30, 2020 at 11:10 PM 1
Share

Transform.Translate doesn't know anything about the vector you give it. If you give it transform.up it can only see the data that represents that vector, so it doesn't know that you are giving it a local vector. It will transform any vector you give it into local space, regardless of where that vector came from.


When I say that it is transfor$$anonymous$$g the vector into local space, all that means is that it is taking whatever vector you give it, then applying the rotation of your object to it. So if you start with Vector3.up it will rotate it by the objects rotation and you will get your objects up vector, which will equal transform.up. But since transform.up is just another vector, when you transform it into local space it will take that vector and rotate it again by the rotation of the object.


Vectors themselves are all inherently in global space. When you are talking about your "Local Up Vector" that simply means the vector in global space that corresponds to the up direction of your object.

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

194 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 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

Instantiateon custom rotation doesn't work 2 Answers

Move object on local axis instead of world axis after rotation 0 Answers

how to move an object, but make it stay on the ground 1 Answer

Combining 2 Rotations: Global and Local 2 Answers

Get child position in world space 4 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