BeastCoder
BeastCoder

Reputation: 2741

What Happens When Setting transform.up in Unity

What happens when I set the transform.up value in unity. Specifically could you explain this video in the link below

https://youtu.be/_XdqA3xbP2A

I know it changes what the object is looking at. But, does it look at a position, or how does it work? What happens when I change the direct transform.up? I can’t seem to find a good explanation. Why does the vector in the video make a direction that is facing the mouse, why not use the mousePosition itself instead of subtracting?

Aside from that could you also explain what is going on in the video?

Thanks in advance!

Upvotes: 1

Views: 5804

Answers (2)

user10091243
user10091243

Reputation:

Basically, when you move an object, you take its position and rotation as reference, so if you increment +1 on the Y position of an object and this object is rotated, you'll increment on that direction. enter image description here

but with Vector3.up, you use the world space as reference, so enter image description here

i want to give you a full answers here, but i would have to enter with some math, simplifying, the transform.up is the direction which the sprite is pointing, he gets the direction saying this: enter image description here

"mousePosition.y" (GREEN) is the position Y of the mouse, and "mousePosition.x" (RED) is the X position of the mouse, with this two values, you have a coordinate, or a direction (Blue traced line), which unity transforms to quaternions and apply the value to your rotation (this in 2d). you want to use the Vector3 which uses a world space reference, because if you use a local reference, would happen something like this enter image description here

and you would get the wrong direction.

Upvotes: 3

ashemez
ashemez

Reputation: 120

Transform object automatically calculates a quaternion rotation using this up Vector like from default Vector3.up to new transform up vector.

Upvotes: 3

Related Questions