- Home /
 
 
               Question by 
               frankyboy450 · Dec 12, 2013 at 10:03 AM · 
                c#transformmovey  
              
 
              Move Object A's Y position towards Object B's Y position
Hi. I'm attempting to make one object move towards another objects Y position.
I have 2 variables.
One called myTransform and one called playerTransform that I set in the start function
and I have this line in the update function.
 myTransform.position.y = playerTransform.position.y;
 
               I get an error when writing it. I'm guessing it isn't possible to write it like this :/
Does anyone have a solution to this?
Thanks :)
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by GameVortex · Dec 12, 2013 at 10:10 AM
I am guessing you are using C#, because you can only write it like that in UnityScript.
You have to modify the entire Vector3 position instead, so try making a new Vector3 which does allow you to modify its values directly:
 Vector3 newPosition = myTransform.position;
 newPosition.y = playerTransform.position.y;
 myTransform.position = newPosition;
 
              Your answer