Question by
andyRogerKats · Oct 02, 2016 at 12:35 PM ·
rotationpositionvector3
How do I make obj1.transform.position.y = obj2.transform.rotation.y
I cant seem to get this one. I know it has something to do with putting transform.position into a temp variable. All I want to do is use the value of the rotation y of obj2 and make obj1's position y always the same value. Any advice will help, thanks
void Update ()
{
obj1.transform.position.y = obj2.transform.rotation.y;
}
Comment
I'm working on a dial that when matching turned it also will go up and down. hence needing position to equal the rotation. The dial is attached to a parent object (obj2).
Best Answer
Answer by JedBeryll · Oct 03, 2016 at 05:55 AM
You can't change just the y, you need to reassign it:
obj1.transform.position = new Vector3(obj1.transform.x, obj2.transform.rotation.y, obj1.transform.z);
Note that rotation is a Quaternion, if you are looking for the rotation vector, use transform.eulerAngles.
Answer by andyRogerKats · Oct 04, 2016 at 11:32 AM
Thanks! That's it. Quaternions are confusing :/ @JedBeryll