Howdy everyone!
Today I wanted to post a simple snippet that will solve all your physics needs in Game Maker Studio’s GML language. Sure, Game Maker will do physics for you, but for a platformer, where physics is one of the most important aspects of the game design, why not write your own so that it feels exactly right! Anyway, just pack this bad boy into a script and enjoy! If you get adventurous, feel free to start tweaking it to make it your own!
Also, some of you may notice that this could be done more simply or compactly. Generally I like for my code to be readable, especially for a small, side scrolling game that’s not very taxing.
var grav_speed = argument0; var vspeed_max = argument1; // if jumping if vspeed < 0 { // if nothing above if place_free(x, y+vspeed-1) { gravity = grav_speed; } // if something above else { move_contact_solid(90, abs(vspeed)+1); vspeed = 0; } } // if at top of jump else if vspeed == 0 { // if nothing is below if place_free(x, y+1) { gravity = grav_speed; } // if something is below else { gravity = 0; vspeed = 0; } } // if falling else { // if nothing is below if place_free(x, y+vspeed+1) { gravity = grav_speed; } // if something is below else { gravity = 0; move_contact_solid(-90, vspeed+1); vspeed = 0; } } // limit vspeed if vspeed > vspeed_max { vspeed = vspeed_max; }