x


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.

more ▼

asked May 08 '11 at 12:37 AM

Irsan gravatar image

Irsan
65 39 42 50

(comments are locked)
10|3000 characters needed characters left

1 answer: sort newest

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;

    }


}
more ▼

answered May 08 '11 at 12:58 AM

Thomas Paniagua gravatar image

Thomas Paniagua
41 15 17 19

Wow, it worked. Thanks!

Now is there a way to move it relative to the camera's rotation?

May 08 '11 at 01:06 AM Irsan

Yes, move it in the direction of Camera.current.transform.forward instead of on the global x-axis.

May 08 '11 at 01:28 AM Joshua

I noticed that the object isn't taking its own rotation into account. It seems to move relative to the world position instead of its own local position. using "localPosition" doesn't work apparently.

May 08 '11 at 02:37 AM Irsan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1371
x268
x90
x31

asked: May 08 '11 at 12:37 AM

Seen: 1558 times

Last Updated: May 08 '11 at 12:37 AM