vrijdag 14 januari 2011

Stick to the path

Dear readers,

As I mentioned last week I'm continuing work on the boss level of our platform game. One particular problem I was facing is that the boss has to follow a certain path. This path is shown in the image below.

The purple line shows the path the boss should follow in this level

In physics straight paths are fairly easy to do, but paths like this are a lot harder (as far as I know). You might apply the correct forces at every point on the path so the boss exactly follows the path, but when the player character is blocking the path, the boss will slightly be pushed off the path. Then you'll have to compensate in order for the boss to continue to follow the path. I suppose it's not impossible, but I do foresee many fine-tuning problems. Therefore I chose to use a spring-like solution. But first we have to get the path into our program. For this I use a bezier curve. Unfortunately the program we program in does not support bezier curves. Instead I create the curve in a 3D editor (the same with which we design our levels) and at every X distance along the curve place a marker.

Markers placed at every 0.1 distance along the curve
 
Then in-game I read all markers and use these to attach a spring between this point and the boss each frame. As a result the boss will follow the path and even when it gets slightly off-path because the player is in the way, the springs will automatically pull it back to the path.

-- Stijn

Geen opmerkingen:

Een reactie plaatsen