Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: Platformer Movement Bug  (Read 1297 times)

0 Members and 1 Guest are viewing this topic.

Ryuza

That one guy
Platformer Movement Bug
« on: June 14, 2010, 04:38:22 pm »
  • RyuKage2007
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 290
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:
Code: [Select]
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.
Logged
<- Koholint Island - MC Style  <- Link's Awakening Photo Recolors  <- Wind Waker 3D Resources <- Super Mario Bros Crossover
  • RyuKage2007's Youtube
Re: Platformer Movement Bug
« Reply #1 on: June 14, 2010, 05:21:17 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Posts: 2245
when you're stuck in a wall and hspeed/vspeed is 0 it will cause an infinite loop.

at a guess if you run into an object at a speed greater than one then your check x -/+ 1 will catch it after you're already inside the object and set it to zero
Logged

Ryuza

That one guy
Re: Platformer Movement Bug
« Reply #2 on: June 22, 2010, 08:36:02 pm »
  • RyuKage2007
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 290
Ah, do you know how I might go about fixing that?
Logged
<- Koholint Island - MC Style  <- Link's Awakening Photo Recolors  <- Wind Waker 3D Resources <- Super Mario Bros Crossover
  • RyuKage2007's Youtube
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.096 seconds with 44 queries.