|
Hi, I have an issue with up vectors. I am working on island demo scene and i have the following piece of code
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
But again I get (0.0, 1.0, 0.0). I get (0.0, 1.0, 0.0) even with
where cm is the main camera. So, what is the correct way to obtain the vector in world space?
(comments are locked)
|
|
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 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.
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. 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?
Jul 23 '10 at 01:07 PM
Patrik
I edited my post.
Jul 23 '10 at 01:28 PM
Peter G
yes, yes, I get this. Maybe 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)
Jul 23 '10 at 01:53 PM
Patrik
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.
Jul 23 '10 at 02:21 PM
Peter G
(comments are locked)
|

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