- Home /
instant move an object to a position + offset value
hi,
im trying to use the seek steer script from the unity wiki. i want it to follow the player object by an offset value.
eg : steer to a point just a little above and behind the player.
im using an empty game object called waypoint and updating it to the player position.
the script works fine when i assign the player transform directly to the waypoint every fixed update()
as
player = GameObject.FindGameObjectWithTag("Player");
waypoint.transform = player.transform
or
waypoint.transform.position = player.transform.position;
however i am unable alter the position with offset.
i have tried to assign waypoint.transform.position with player x,y,z coodinates and also the transform.translate() both to no avail.
i would appreciate a code with an example of how to do this.
thanks and regards.
Where are you setting your offset? You want an offset, but I can't see where you're applying it. All I can see is that you're setting the waypoint position to the player position.
i was trying
waypoint.transform.position = Vector3(player.transform.x , player.transform.y + 20 , player.transform.z + 20);
Answer by pvpoodle · Nov 11, 2013 at 04:11 PM
i think i have it figured out now.
i was not using the "new" keyword , which was what was causing problems for me.
just for anyone else having the same kind of problems , the code im using now is
waypoint.transform.position = new Vector3(player.transform.x , player.transform.y + 20 , player.transform.z + 20);
I think has changed since 2013. The new code for those wondering that I'm using is`player.position = new Vector3(transform.position.x, transform.position.y - 0.66f, transform.position.z + 20);` Note if you want to use decimal values, you have to type the "f" in at the end of the value, because unity cant convert the double value to a float.
Your answer

Follow this Question
Related Questions
Storing transforms from objects in Array 1 Answer
Place a object in front the camera in the coordinate 0 of Y axis 2 Answers
Trying to set up some GUI using planes and textures. Need help with dynamic changes. 0 Answers
Two gameobjects with the same transform 1 Answer
HealthBar for 5 Objects 3 Answers