friction

The friction to apply to the object.

Syntax:

GML Code Example

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:

GML Code 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.


Next: gravity



These examples are submitted by the community. Upvote the examples you think are most helpful.

friction by /u/tmcicuurd12b42 on January 19, 2017

GML Code

///Create Event
motion_set(-45,8);
friction = .05;

/*
See it in action:
https://yal.cc/r/gml/?mode=undefined&lzgml=MQEwpgZglgdmAEBbAhrAUAeg-WUAu8AxgPbjwAWYATmGosXlMTAPoDOYeAFALQAsAVgA0ADgCUAbjQQqUQo2bwAvPAB0ABgFS0oSLARs8YAA6ZsAV2MhkRoqQSUaaHeGhx4IKsgDuZj1+87MkdaTx8WIwAPbkihAE8hNmMwMBBJZyA
*/

Edited On January 19, 2017

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here