Positioning and Re-positioning

Something is somewhere in your world, and you want to re-position it. How is this done? I currently have this:
transform.position = new Vector3 (0,0,-49);This works if you want to position something precisely on a point, but what if I just want one or two coordinates to be specific and the other coordinate(s) to be the initial point it was on when the code executed.

For example, an object that is on 10,10,10 would be set back to 10,10,0. If it was 15,77,39, it would be set back to 15,77,0. It remembers it’s current location and only adjusts specific coordinates.

1 Like

transform.position = new Vector3 (transform.position.x,transform.position.y,-49);

Or use .translate

Ah, thanks appels. Is this a common way to create boundaries? If I just tell it to go back to the exact coordinates it seems to be a seemless way to create ‘invisible walls’. This works well for simpler games. Thanks a lot!

hippocoder, would you explain your answer to me a little?

Oh right, didn’t read. Yeah, best way is by using .position to reset it back when it goes over I’m afraid.