Hello everyone…
I just want my camera to move towards my player.
For that i tried :
gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition ,target.transform.localPosition , 2);
But i just want to move my camera on x-z axis. Y position should not be changed.
Which method shall i use ?
Thanks…
1 Answer
1
Just make a new Vector3 and only give it the x and z values of the target
gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition , new Vector3(target.transform.localPosition.x,0f, target.transform.localPosition.z), 2);
or
gameObject.transform.localPosition = Vector3.MoveTowards( gameObject.transform.localPosition , new Vector3(target.transform.localPosition.x,gameObject.transform.localPosition.y, target.transform.localPosition.z), 2);
This isn't much of an answer but you can just change Y value for your vector.
– revoluteExclude Y values by setting them to the same value when putting in MoveTowards method and set it back to original value. A workaround but easy.
– revolute