# Best way to constrain character to a path?

I'm in the process of developing a level-based runner for mobile phones, and I've hit a wall when deciding which method to use to get the character to move through the level.

Basically - I need my character to travel a constrained path across the level as I manipulate the character by speeding up/down and jumping to avoid obstacles. I couldn't just place a straight path and use Curved World look as I needed a realistic feel to character motion. I also have up/down slopes that have to affect the character's speed.

I'm not use whether using iTween is the best for this as it makes it difficult to manipulate character speed and especially the jumping 'arc'. I've tried using MoveTo() but problems arose when trying to change character parameters... PutOnPath() made sense in theory but I found it harder to implement.

Is there any easier way to go about this? I'm almost completely new to Unity, so an easier implementation is what I'm going for, for now.

If you end up having to roll your own, the common solution to having objects on paths (cameras moving over time, objects moving over time, cars driving in traffic lanes) is to use curves.

Here's a gentle intro to 2d bezier curves I wrote that you can easily extend to 3d.

http://blog.demofox.org/2014/03/04/bezier-curves/

http://blog.demofox.org/2014/03/22/bezier-curves-part-2-and-bezier-surfaces/

And an interactive web demo: http://demofox.org/bezcubic.html

Depending on your implementation and needs, this may not work for you, but one method is to use Unity Navmeshes. The way Navmeshes work is that you select the portions of the level which you want your runner to be able to move in and then bake them. This will then define where your runner can move. You will need to add a NavMesh Agent to your runner. The NavMesh Agent is what tells the object to stay within the NavMesh you defined earlier. You can use SetDestination and the shortest path to the point (that is on the NavMesh) will be calculated. You can also have sloped NavMeshes and define in your NavMesh Agent how steep of a slope it can traverse over.

• This doesn't really do it for me, since in my case I didn't just need to tell the character which plane was walkable but also exactly how to move on that path each Update call (like move a certain portion of an axis). The closest to a solution I got was using iTween's PutOnPath function. You basically "draw" a path for the player to get from A->B, and then use PutOnPath to iterate from 0 to 100% of that path, using Time.deltaTime to smooth the movement. I ended up retreating back to CurvedWorld though, but thanks for the suggestions anyway! – abelegu2 Apr 8 '15 at 12:45