08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

overwritten by the new path. (See a later chapter on how to create and<br />

destroy paths.) The function will return whether a path was found. The<br />

function will stop and report failure if no straight path exists between start and<br />

goal. If it fails a path is still created that runs till the position where the<br />

instance was blocked.<br />

mp_linear_path_object(path,xg,yg,stepsize,obj) Same as the<br />

function above but this time only instances of obj are considered as obstacles.<br />

obj can be an object or an instance id.<br />

mp_potential_path(path,xg,yg,stepsize,factor,checkall) This<br />

function computes a path for the instance from its current position and<br />

orientation to the position (xg,yg) using the indicated step size trying to avoid<br />

collision <strong>with</strong> obstacles. It uses potential field steps, like in the function<br />

mp_potential_step() and also the parameters that can be set <strong>with</strong><br />

mp_potential_settings(). The indicated path must already exist and will<br />

be overwritten by the new path. (See a later chapter on how to create and<br />

destroy paths.) The function will return whether a path was found. To avoid<br />

the function continuing to compute forever you need to provide a length factor<br />

larger than 1. The function will stop and report failure if it cannot find a path<br />

shorter than this factor times the distance between start and goal. A factor of<br />

4 is normally good enough but if you expect long detours you might make it<br />

longer. If it fails a path is still created that runs in the direction of the goal but<br />

it will not reach it.<br />

mp_potential_path_object(path,xg,yg,stepsize,factor,obj)<br />

Same as the function above but this time only instances of obj are considered<br />

as obstacles. obj can be an object or an instance id.<br />

The other functions use a much more complex mechanism using a grid-based approach<br />

(sometimes called an A* algorithm). It will be more successful in finding paths (although it still<br />

might fail) and will find shorter paths but it required more work on your side. The global idea<br />

is as follows. First of all we put a grid on (the relevant part of) the room. You can choose to<br />

use a fine grid (which will be slower) or a coarse grid. Next, for all relevant objects we<br />

determine the grid cells they overlap (either using bounding boxes or precise checking) and<br />

mark these cells as being forbidden. So a cell will be marked totally forbidden, even if it only<br />

partially overlaps <strong>with</strong> an obstacle. Finally we specify a start and a goal position (which must<br />

lie in free cells) and the function computes the shortest path (actually close to the shortest)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!