mp_linear_step

This makes an instance try to get to a position while checking for all other instances.

Syntax:

mp_linear_step(xgoal, ygoal, stepsize, checkall);


Argument Description
xgoal The target x position.
ygoal The target y position.
stepsize The speed the instance moves in pixels per step.
checkall Whether to check all instances (true) or just solid ones (false).


Returns: Boolean


Description

With this function you tell an instance to take a "step" towards a specific point, specified by the xgoal and ygoal values. The size of the step (which is how many pixels the instance should move each step) is indicated by the stepsize, and if the instance is already at the position it will stop and not move any further, contrary to other, simpler functions like move_towards_point. The stepsize is also the distance "ahead" that the object will check each step for a collision, and you can choose whether the instance stops at a collision with any instance or only those that are flagged as solid.

Note: This function does not try to make detours if it meets an obstacle, it simply fails and stops moving. The function will return whether it has reached the goal position (true) or if it has failed (false).

Example:

if mp_linear_step(mouse_x, mouse_y, 5, 0)
   {
   instance_create(x,y,obj_Explosion);
   instance_destroy();
   }

The above code will make the object move towards the mouse at a speed of 5 pixels per step. Once it reaches the mouse position it will create an object "obj_Explosion" and destroy itself.


Back: Motion Planning
Next: mp_linear_step_object
© Copyright YoYo Games Ltd. 2018 All Rights Reserved