friction

The friction to apply to the object.

Syntax:

friction


Returns: Real


Description

All instances in GameMaker: Studio have certain "built in" properties that you can use and set to govern how they look and behave. Friction is one of those properties and can be used to slow the instance down over time when the speed is greater than zero. It works simply by subtracting an amount from the speed every step until the object has a speed of 0, so if the friction is set to, for example, 0.1 and the speed of the instance is 1 (1 pixel per step), it will slow down and stop after 10 steps have passed. Note too that the friction is applied to positive and negative speeds equally with the net result always being that the object has a speed of 0 after a given time.


Example:

if abs(speed) > 0
   {
   friction=0.05;
   }
else
   {
   friction=0;
   }

The above code will only apply friction if the instance's absolute speed is above 0.


Back: Moving Around
Next: gravity
© Copyright YoYo Games Ltd. 2018 All Rights Reserved