motion_add

This function accelerates the instance with the given speed in the given direction. 

This is the equivalent of calculating the x component and y component of the given speed in the given direction, and then adding them to hspeed and vspeed respectively.

If you wish to simply set a speed instead of accelerating gradually, use motion_set().

 

Syntax:

motion_add(dir, speed);

ArgumentTypeDescription
dirRealThe added direction.
speedRealThe added speed.

 

Returns:

N/A

 

Example:

var pdir;
pdir = point_direction(other.x, other.y, x, y);
motion_add(pdir, other.speed);
if speed > 8 speed = 8;

The above code would be called in the collision event with another object. It adds to the direction of motion and the speed of the instance a vector based on the position and speed of the other instance involved in the collision. It then limits the speed if it goes over 8 (pixels per step).