Question by
Scurt · Oct 31, 2015 at 09:28 AM ·
positioningmove an objectpositions
How to Move a GameObject to a fixed position
Hello,
I have a GameObject at position (3.0, 2.0, 0.0)
and I want to set it at position (10.0, 2.0, 0.0)
I' know I can move a GameObject using transform.Translate by passing a Vector3 with the movement I want. That mean It will move the object based on it's current position. In this cas I should pass a Vector3 (7.0, 0.0, 0.0)
.
I also know I can calculate this Vector3 based on my current position and my wanted position.
But is there a way to set my position to (10.0, 2.0, 0.0)
without knowing my current position? Something like :
Vector3 newPos = new Vector3(10.0f,2.0f);
myGameObject.transform.position(newPos);
Which I know I can't use.
Thanks and Regards, Eric
Comment
Best Answer
Answer by hexagonius · Oct 31, 2015 at 10:39 AM
Vector3 newPos = new Vector3(10.0f,2.0f,0f);
myGameObject.transform.position = newPos;