- Home /
Is it possible to assign a quaternion value to the position vector of a object?
i have the following code: var distance : float =6.4;
function LastUpdate()
{
var currentRotation = Quaternion.Euler(0,90,0);
transfomr.position -= currentRotation * Vector3.forward * distance;}
i want to know how it is possible to assign a Quaternion value multiplied by a Vector 3, multiplied by a float value; i mean what is the result?
P.S. Sorry for bad english :)
What you want to do with that code? $$anonymous$$oving a character forward? So i'm sure it won't work, try to use transform.forward(if the script is attached to the character) or player.transform.forward (player is the GameObject that you want to move) ins$$anonymous$$d of Vector3.forward
What are you trying to accomplish, that might help us answer. Quaternion.Euler(0,90,0) should be same general idea as Vector3.up, no? $$anonymous$$aybe that's what you wanted?
sorry for my lack of knowledge about Quaternion,maybe robertu answer is what you need.
And also, why my comment be the answer... I remember exactly that i wrote a comment not answer...
Answer by robertbu · Aug 12, 2013 at 09:45 PM
Yep, you can a multiply a Vector3 by a Quaternion to rotate that vector. Note you cannot do it the other way around (multiply a Quaternion by a Vector3). Also note 'transform' is misspelled on line 4 of your code above. I believe your code here is equivalent to:
transform.position -= Vector3.right * distance;
Quaternion(0.0,90.0,0.0) * Vector3.forward - takes the world forward and rotates it 90 degrees, so you end up with World right: (1,0,0);
You multiple world right by distance so you end up with a vector (distance,0,0);
You subtract that from transform.postion, moving left by 'distance'.
Your answer
Follow this Question
Related Questions
Shader input position.w, what is it for? 1 Answer
Camera rotation around player while following. 6 Answers
change position and play animation 1 Answer
Unity 3 Animation Positioning Problem 1 Answer
Vector3.Lerp doesn't work! 1 Answer