← View other scripts

The Most Simple Movement Code

Very simple collision code.
Lv. 37
· 2 min read · 4742 views
Welcome! It looks like you're visiting from outside our community.
This free script was submitted by a member of our Game Maker community. If you're interested in finding out more about game development, game jams or GameMaker Studio 2, check out these links below.

The Code:

repeat(abs(hsp)) {
    if (!place_meeting(x + sign(hsp), y, obj_block)) {
        x += sign(hsp);
    } else {
        hsp = 0;

repeat(abs(vsp)) {
    if (!place_meeting(x, y + sign(vsp), obj_block)) {
        y += sign(vsp);
    } else {
        vsp = 0;


  • You need to initialize the variables hsp and vsp and have an object named obj_block
  • Obviously this isn't as optimized as other solutions, but that shouldn't be an issue for most games
  • This version won't cause instances to teleport through walls when moving at extremely high speeds
  • This is designed to be pixel perfect, so an hsp of 2.4 will move as far as an hsp of 2.0