April 4, 2019

Collision Check in Game Maker Studio 2

Collision Check in Game Maker Studio 2

To check the collision between your current object and another object Game Maker Studio 2 provides the helpful function "place_meeting" which takes 3 arguments. The first one is the x coordinate of your current object and the second one the y coordinate. The third one is the object you want to check collision against.

Here a simple example:

if (place_meeting(x, y+1, obj_ground) {
    y_speed = 0;
}

The script above checks if there is a collision between the current object and the object "obj_ground" beneath it. When this returns true we set the y speed to zero to stop the current object from falling.