- Home /
Creating Hint Vector
long story short, I need to create a function like transform.LookAt or Quaternion.LookDirection that doesn't use Vector.forward as the direction or to find a way to create a hint vector in a function like Quaternion.FromToRotation.
I am more then aware of the two vectors needed in those function, that is indeed why i want to change the axis it is operating on. and as true as it is that you can assign them... its not much more then a rotation, which in this perticular case doesn't help. tho I realize there are many different ways of attack this current problem. if I had a function like Quaternion.AngleAxis that set a group of local rotations... i would also be fine...
So do you want to just do a relative rotation? Something like: You have a local arbitrary direction vector which should point into a certain direction. So you want to rotate the object that this vector (which is fix in local space) should point into / to a certain world space direction / point? If so, why not just using Quaternion.FromToRotation like you've mentioned? It calculates a rotation which rotates a given vector, so it points into the direction of "toDirection"
Example:
Vector3 localVector = (new Vector3(0,1,1)).normalized; // forward but 45° up
transform.rotation = Quaternion.FromToRotation(localVector,targetDirection);
I've tested it and it works like you would expect. Of course without a second vector the rotation around the direction vector might look a bit strange, but a single vector doesn't define a whole coordinate system.
without an up vector defined, my ship takes routes that aren't helpful, tho I realized my problem was actually converting a world rotation to a local rotation... and LookRotation was working very well.
Answer by Bunny83 · Apr 24, 2012 at 07:44 PM
Well, the calculations behind lookat aren't that complicated, but are you aware of that you need two vectors? LookAt takes one direction and one up-vector and aligns the z-axis with the direction and the y-axis "in the direction of" the given up-vector.
As far as i know you can simply assign a vector to transform.up to make the upvector point into that direction, but i never used this.