← View other scripts
script
The Most Simple Movement Code
Very simple collision 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
hsp
andvsp
and 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
hsp
of2.4
will move as far as anhsp
of2.0