Hey all, I've been using this movement code I found a long while back and I've been modifying it here and there over time. Recently though I've had trouble with GM8 freezing up at random times during testing, sometimes after a simple jump or walking into a corner or something. I was hoping someone might be able to tell me if theres anything weird or buggy looking in this code, maybe something that causes an unwanted loop or something that could cause GM to freeze up.
This code goes into the Step Event:
if keyboard_check(vk_left) {
x -= global.pfric
} else if keyboard_check(vk_right) {
x += global.pfric
}
// Here, we move horizontally..
x += hspeed;
// Then move out of any collisions we just moved in to.
while place_meeting(x, y, par_solid) x -= sign(hspeed) / 2
// Now we move vertically..
y += vspeed;
// Then move out of any collisions we just moved in to again.
while place_meeting(x, y, par_solid) y -= sign(vspeed) / 2
// Because we moved out of collisions, we can use simple codes to check for collisions.
// Here, we check the right and left walls.. Easy to make wall jumping, or something like that.
if place_meeting(x - 1, y, par_solid) && hspeed < 0 hspeed = 0;
if place_meeting(x + 1, y, par_solid) && hspeed > 0 hspeed = 0;
// Then, we check for the ceiling.
if place_meeting(x, y - 1, par_solid) && vspeed < 0 vspeed = 0;
// Finally, check the floor..
if place_meeting(x, y + 1, par_solid) {
// If there is a floor there, we need to stop falling.
if vspeed > 0 vspeed = 0; global.djump = false;
// We can also jump with a floor below us.
if keyboard_check_pressed(vk_up) vspeed = global.pjump
}
// If there is no floor, then we need to fall down.
else vspeed += global.pgrav
// Finally, friction.
hspeed *= global.pfric
// Left right movement. (It's all very simple.)
if keyboard_check(vk_right) hspeed += 1 global.pdir = "R";
if keyboard_check(vk_left) hspeed -= 1 global.pdir = "L";
/* Negates the effects of using hspeed and vspeed, so that we can handle the
variables ourselves. */
x -= hspeed; y -= vspeed;
If anyone has anyone has any ideas as to whats wrong please let me know.