The Most Simple Movement Code
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
hspandvspand have an object namedobj_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
hspof2.4will move as far as anhspof2.0
Related Scripts
Browse these game resources from the community
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.
Very Simple Particle Effects
Create a very simple particle effect that you can call from just one 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!
Why Join a Game Jam
Looking for a new challenge as a game developer? Consider participating in a game jam!