- Home /
Extremely simple movement.
I'm working on a grid-based movement system. I have a regular 1x1x1 cube. Let's say I want it to move forward 1 unit. I'll press the W key, and the cube will set a new position 1 unit forward relative to its initial position. All the movement systems I've seen here are smooth. I want one that "teleports" the object in a certain direction and distance.
Answer by Thomas Paniagua · May 08, 2011 at 12:58 AM
An easy way is telling the distance in whatever (x, y or z) you are using and then use this code,
function Update () {
if (Input.GetKey ("up")) {
transform.position.x += the_distance;
}
}
Wow, it worked. Thanks!
Now is there a way to move it relative to the camera's rotation?
Yes, move it in the direction of Camera.current.transform.forward ins$$anonymous$$d of on the global x-axis.
I noticed that the object isn't taking its own rotation into account. It seems to move relative to the world position ins$$anonymous$$d of its own local position. using "localPosition" doesn't work apparently.