47th GM48
script

The Most Simple Movement Code

Very simple collision code.
The Most Simple Movement Code
Yosi
Lv. 46
Yosi Level 46
· 2 min read · 5566 views

The Code:


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

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

Notes:

  • 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

Browse these game resources from the community

script

My tower defense EnamyFactory constructer function

With this script you will be able to easily create new enemy types for tower defense games using just one calling object.

script

Very Simple Particle Effects

Create a very simple particle effect that you can call from just one script!

script

Super Easy Screen Shake

A little screen-shake effect can make all the difference, here's a super easy way to add one to your game!

Official resource

Why Join a Game Jam

Looking for a new challenge as a game developer? Consider participating in a game jam!

From Idea to Game in 48 Hours

Join thousands of GameMaker developers who have discovered the joy of game jams.

No experience? No problem. GameMaker developers of all skill levels and backgrounds use the gm(48) game jam to create games, learn new skills, and connect with the community.

Ready to start your game development journey? Create an account and join the next gm(48) game jam!