It's only frustrating because you've been given poor advice. The code from TheouAegis is misbehaving because it is mixing both custom movement and built-in movement, so it's moving twice and you're only controlling one of the two systems directly. You should completely remove
hspeed and
vspeed from your code, and substitute it with your own variables
xspeed and
yspeed.
Script:
handle_movement
Code:
if place_meeting(x+xspeed,y,obj_solid) {
var i = sign(xspeed);
while !place_meeting(x+i,y,obj_solid)
x += i;
xspeed = 0;
}
if place_meeting(x,y+yspeed,obj_solid) {
var i = sign(yspeed);
while !place_meeting(x,y+i,obj_solid)
y += i;
yspeed = 0;
}
Create:
Step:
From here on you will manipulate the speed using
xspeed and
yspeed exclusively. No more
hspeed or
vspeed.
The cardinal rules for custom pixel-precision movement:
Rule #1: If you decide to implement your own movement, there should NOT be a single
hspeed or
vspeed in your code (the built-in variables).
Rule #2: You should completely understand the pixel-precision movement algorithm before you use it.
Rule #3: Once you understand the pixel-precision movement algorithm, you should not type out the code again. Pack it into a script and take it with you, lest you make the same kind of typo TheouAegis did.