More Unity: Part 2 (Path Following and Bezier Curves)

More Unity: Part 2 (Path Following and Bezier Curves)

Part 1 talked about using triggers as checkpoints for the player. It was a relatively basic concept that I was able to implement after I learned of the useful component of triggers. After I did this I noticed that I would probably want a system in which the bike can turn corners and follow the path without having the user do anything. This would have to be implemented because by the time my project would be finished, there would be no turning mechanism that the user could input.

Making an object follow a path is rather straight forward if you want a very basic path, but my path is going through steep terrain and turns which is quite difficult to make an object follow.

I visited with my onsite advisory, Rodrigo, and  he brought up the ingenious idea of using Bezier Curves for a path following mechanism. Bezier are a bit complicated but I will try to explain.

In short , Bezier Curves are parametric equations that are often used in computer graphics and similar fields. For simplicity, we will be looking at a two point Bezier Curve. If you have two points Po and P1 and you want an object to follow the path between those two points then you step up a basic equation…

\mathbf {B} (t)=\mathbf {P} _{0}+t(\mathbf {P} _{1}-\mathbf {P} _{0})=(1-t)\mathbf {P} _{0}+t\mathbf {P} _{1}{\mbox{ , }}0\leq t\leq 1

This equation tells you the percentage of each point you are at. You can think of t as the percentage at which you have completed the path. If t is at 0.75, then P1 is going to be a greater value than Po so your final position (B(t)) will be closer to P1. This concept can be better visualized below…

A two point Bezier Curve is the simplest form and as you add more points the equation and concept gets more complicated. Below you can see a Bezier Curve with 4 points…

What I am working on is to create Bezier Curves that follow my Mount Lemmon road. Once I do that then all I have to do is to have my bicycle follow the path by making it the point in the path similar to the point in the first picture.

Farewell till next post where I talk about trying to accurately place the Mount Lemmon road onto my terrain!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s