Creating the road

In order to have a character follow a path we first needed to program a path. Since we wanted a curvy path instead of a boring straight path, we needed splines for that.

We used the cubic bezier method to calculate spline points between two ‘nodes’ with each having 1 helper point to define the curve.

Then by linking different of these segments after each other where the endpoint of the first segment is the begin point of the next segment, and so on, we get one long curve. To get a smooth transition from one segment to the next we needed to calculate a specific position for the control points(P1 & P2). The rule to get a smooth transition is that the line from the control point of the end point of the first segment(P2) to the end point(P3) needs to be parallel with the line from the start point of the second segment(same as P3) to the first control point of the second segment.

So now the only thing we need as input to be able to calculate a road is some node points that are placed in the level. To visualize the road when creating a new road we made a unity editor for that.

roadCapture

Now it’s a matter of making the player seek for the closest point on the spline and then make him move in the direction to the next point to make the player follow the road.

Capture

We also added functionality for adding sub-roads to the road since we want sub-tracks in our game where the player will have to pick a side.

Plaats een reactie