Incremental movement...

Ok, here’s a question that may sound odd:

I want to be able to move a character fixed amounts, i.e., move him like one might move on a gameboard. Every time the user hits an arrow key, the character moves a fixed distance then comes to an immediate halt.

All the scripts in the hints and tips use the key to apply a vector of force to the character, so I’m struggling with how to do this. Any hints?

Transform.Translate

Hmm.

And here I was trying to use SimpleMove.

I guess you’re using the character controller? SimpleMove seems to be a way to approximate physical velocity without using a rigidbody etc. It’s great for “real movement,” but you want to have your character just “pop” from one place to another, right? In that case, just change the position of its Transform.

You may not need the character controller if movement is all you wanted it for.

Yeah, I got it to work nicely with transform.translate. Now my issue (which is in another thread) is that I need the character to not be allowed out of the level - since transform.translate seems to be sort of teleporting, and a collider wont block it.

I would suggest casting a ray using Physics.Raycast and checking to see how far away the collider it hits is.

Either that, or check the X/Z position, and if it’s less than or greater than the bounds of the level, disallow the move.

–Eric

If you are using the character controller already then you should use:
controller.Move ();
Which takes an offset in meters and not a velocity like SimpleMove.

Ahh. Ok.

Will this sort of movement recognize colliders between the character and its destination? So that I can simply throw a ring/box around my level to stop the character from being able to leave it?

the Move function and the SimpleMove function both handle collisions.
The SimpleMove function takes velocity, the Move function an absolute movement. The SimpleMove function also automatically handles gravity for you, where the Move function simply attempts to move the character with the given movement vector performing collision detection on the way.,

As usual with Unity: it’s easier than it seems!

Indeed.

The awesomeness of Unity is not to be underestimated. Thanks Joachim!