- Home /
instantiating a cube so a side is parallel with a Vector
Im looking to have a cube adjust its side in the same direction as a vector in my scene. I was wondering if anyone knows a good place to start with this. the main thing im having trouble figuring out is the alignment when instantiated to be parallel with a vector. Please help!!
Answer by robertbu · Feb 20, 2014 at 01:17 AM
There are infinite number of solutions to aligning anything with a vector. I think you need to supply more information about your situation. Let's say you want to align the sides of your cube with a vector. The forward vector of the cube is aligned with the sides so you can do:
transform.rotation = Quaternion.LookRotation(theVector, transform.right);
This will align the sides with the vector using transform.right (if possible) as the axis of rotation.
Another possibility:
transform.rotation = Quaternion.FromToRotation(transform.forward, theVector) * transform.rotation;
And yet another:
transform.forward = theVector;
Your answer
Follow this Question
Related Questions
How do I control the transform.position of an instantiated prefab? 2 Answers
How do I rotate a transform to align with a velocity vector? 1 Answer
transform position vectorially 2 Answers
just update X and Z position of gameobject 1 Answer
Rotate an object around another object at an angle from the X axis? 1 Answer