I have 2 vectors, defining an object’s orientation… UP and Right
but there seems to be no way to set an object’s orientation using vectors.
In Unity you can set the object’s transform->forward OR Right OR up, to orient an object, and all of these are ambiguous, you cannot control the rotation around that axis (using the second vector) unity decides for you what angle that will be.
isn;t there a way to construct a transform from 2 vectors ? or to set object’s rotation ?
There must be a simple way to do this please
help appreciated, thanks.
I’ve read through the above a couple of times and I’m not too sure what you’re asking… but there are several functions in vector3 that work out rotations/angles based on 2 vectors:
and I’m fairly sure you could just add the UP and RIGHT vectors to get UPandRIGHT (normalize it if you want a magnitude 1 vector as output)
This function uses for forward and up vectors, but you can easily get your forward vector by calculating the cross-product from your right and up vectors.
awesome, thats what I was looking for, thanks much !!!
yep I actually have all 3 vectors already, calculated using .cross, just couldn’t spot a way to do the unique orientation.
cheers
Hmm ok, I thought it was awesome until I tried it out…
ok so if I individually just set transform.forward = myForward
OR transform.right=myRight
OR transform.up=myUp
…then it orients my object’s chosen vector perfectly to the moving surface I’m trying to attach it to… confirming that I have correctly calculated vectors that describe the surface and orientation that I want. for up/right/forwards.
However my object is always facing in the wrong direction (as I only provided 1 vector, which isn;t enough information to fully orient an object) no surprises so far. this is as expected.
However…
if I set the position using 2 vectors, transform.rotation.setLookRotation(myForward, myUp);
(which should then be enough information to orient perfectly)
what I end up is with none of the axis looking right,
also I added rendered gizmos, so I can see my up/at/right and they are perfectly oriented and attached to the moving surface as intended…
but using transform.rotation.setLookRotation(myForward, myUp);
…does not put the object at the same orientation !!! is it broken/bugged ?
I set the forward to my calculated forward.
Then get angle difference, between the current right vector,and myRight… then rotateAround the new myForward, so current vector matches myRight.
Works perfect.
I’m pretty sure SetLookRotation must be bugged. or at least needs a more comprehensive description in the docs.