Restricting character movement to a path

I’ve been looking to try and restrict my characters movement to a path, but it doesn’t seem to be as simple as linking it to a path and running the game (surprise).

I’m wondering if someone has done a tutorial on this or previously done it themselves.

Is it possible to have a path with junctions on it that the character can change direction on?

The character I’ve got set up at the moment works fine moving around on a 2D plane, but I’d like to fix him to a gridded path to restrict is overall movement, I also plan to have the AI use this path to randomly travel around in the hunt for him.

So it’s basically Pacman if you haven’t worked it out :smiley:


Maybe this will be useful:

Thanks Koko, that sounds like a perfect solution for the AI characters. I’ll give it a whirl.

I don’t think it will help with the movement restriction of the player character though, as it’s controlled by keys and not AI.

I’ve tried using the physics system for negotiating the maze, but it’s too unruly for arcade style precision as I’m using xloc updates to move the character and trying to avoid things like force to move the character.

With that the only ideal solution I can think of is having a gridded path that the character is the child of, so its movement is restricted to being on the path no matter what direction is pressed. This should feel fine to the player as the character control is locked to 4 way direction.

In theory attaching a character to a path sounds easy, but it seems that the game engine logic doesn’t like that as a set up.

I’ve been thinking about this lately myself. I guess “thinking” should be replaced by “experimenting” here to really find out how this could be done :slight_smile:

Here’s a nice video showing the method in practice. Adds a whole new level to a sidescroller (even if just a visual level). Perhaps the video will provoke others to share their thoughts on this :wink:


You could try placing none-rendered objects with collision turned on at the edges of the path. (Model the walls but set them so they aren’t rendered.)

It’s my understanding that this is a common technique in most if not all commercial 3d games. Invisible boundaries prevent the player from straying from the path and complex scenery geometry is set to no collision so all the faces don’t have to be calculated for physics.

Good luck.

Edit: Oops. Didn’t read the thread properly. This isn’t what you’re after, I don’t think.

Edit 2: Maybe if you implement the nodes for the AI then you could reuse them for the character. Store the location of the player within the node map and use the nearby nodes to constrain the player position. ie. If the player is moving along x axis between 2 nodes then they can not move along the y axis further than the node’s y position (“node.position[1]”). If there is a node in the y direction at a node then the player can move up to that node’s y position.

Not sure if I’ve explained that too well or if it’s even a good idea, but it might work.