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 Patrik · Jul 23, 2010 at 12:42 PM · vectorspaceworldup

Up vectors are really in world space?

Hi, I have an issue with up vectors. I am working on island demo scene and i have the following piece of code

 GameObject cab = GameObject.Find("LevelObjects/Cabana2/cabanaRoof");
 gt.text = cab.transform.up.ToString();

where Cabana2 is one of the two cabans in the scene and gt is a guitext element. As answer i get (0.0, 1.0, 0.0) which makes me think that the vector is in local space (while api reference says world space). So I tried this

GameObject cab = GameObject.Find("LevelObjects/Cabana2/cabanaRoof");
gt.text = (cab.transform.TransformDirection(cab.transform.up)).ToString();

But again I get (0.0, 1.0, 0.0). I get (0.0, 1.0, 0.0) even with

GameObject cab = GameObject.Find("LevelObjects/Cabana2/cabanaRoof");
gt.text = (cm.transform.TransformDirection(cab.transform.up)).ToString();

where cm is the main camera. So, what is the correct way to obtain the vector in world space?

Comment
Add comment · Show 1
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 Peter G · Jul 23, 2010 at 01:34 PM 0
Share

I edited my post. I said it here so you get a blue envelope.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Peter G · Jul 23, 2010 at 12:55 PM

Unless you have rotated your cabana on either the x or z axis, then the up direction will be the same as the world direction. Transform.up will give you the world space Vector so if Transform.up is Vector3(0,1, 0) and you use Transform.TransformDirection, you will still get Vector3.up. So the number you are reading is correct. And yes, that number is in world space.

I don't think you understand the idea of a direction. Vector3's can be confusing when you first start because they are used for multiple things with different meanings.

  1. They can be used for a position. In this case they will be something like your comment (1440, 35, 511).

  2. They can represent eulerRotations. That is fairly simple to understand. You might have (0, 45, 0).

  3. You can use Vector3's to store Direction. In this case you will get a normalized Vector that is centered at the origin. If you drew an arrow out from the origin through the point, you would get a direction. Hence they are called Vectors. So transform.up creates a Vector3 pointing in the same direction as the local y-axis of the object. If you call transform.forward, you will get something like (0, 0, 1) if your object has no rotation.

Unity makes no differential among the 3. Each function that takes a Vector3 self determines how it uses it. Some might take a Vector3 and use it as a position like transform.position while others take a direction such as Rigidbody.AddForce(). If you wanted to, you could take a Vector3 that was created with a certain use in mind and plug it into a different form.

Comment
Add comment · Show 4 · 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 Patrik · Jul 23, 2010 at 01:07 PM 0
Share

mmm, i think i got where is the problem. cabanaRoof has coordinates (0,0,0) because it is a subobject of Cabana2 (which is located at 1440, 35, 511). So I think I have to add someway the two coordinates and then get the up vector. Any idea how i may do this cleanly?

avatar image Peter G · Jul 23, 2010 at 01:28 PM 0
Share

I edited my post.

avatar image Patrik · Jul 23, 2010 at 01:53 PM 0
Share

yes, yes, I get this. $$anonymous$$aybe I didn't explain myself good enough. I need the up vector of an object using the global center as center, not the object's center. IE, Cabana2 is located at (1140, 35, 511), Cabana2's cabanaRoof is located at (0,0,0) (guess it is relative to its parent object) and finally Cabana2's cabanaRoof's up vecotr is (0,1,). So the up vector I really need is (1140,36, 511)

avatar image Peter G · Jul 23, 2010 at 02:21 PM 0
Share

Ok. It sounds like you answered you own question. If you didn't then maybe you want transform.parent.position + transform.up; That might be the answer.

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

Keeping the player inside the screen? 2 Answers

camera movement in world space, but when the rotated on y axis 1 Answer

GUI in 3D world space "Monitors / Screens / Displays" 1 Answer

how to convert an objects local axis vector to 'world' vector. 1 Answer

Is there a local method for Rigidbody.constraints? 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