Legacy GM Donkey Kong-Style Gravity System

M

MintyPretzel126

Guest
As the title says, I need to create a Donkey Kong style gravity system. I believe I would use an alarm to stay 1 second in the air before falling. As for falling without moving through the air, I'm not sure. Also on the topic of Donkey Kong, how would I make the player restart the room when falling from a certain height? Thanks a bunch, even if you just read this thread. :)

EDIT: So what I think I need to do is combine the code for moving across grass with stone. The code I have for it is this:
if(place_meeting(x,y + 1,OBJ_Grass)){
gravity = 0;
}
else{
gravity = 0.25;
}
I'm not sure how to add OBJ_Stone to it so one doesn't get stuck in the other. Also since I set the speed to 0 when I release a movement key, the falling slows down when I mash the Left and Right keys.
 
Last edited by a moderator:
T

Tonydaderp

Guest
Maybe you should use states. So when your player is in the air, he cant move.
Code:
if (state != state_fall){
//move right or left
}
also, maybe you can make your own gravity variable.
There are lots of tutorials online that show you how.

When falling from a height I think you should use alarms. If you are not standing on ground, alarm[0] is set to a second. If the alarm runs out, you die, but if you hit the ground before a second, alarm[0] is shut down.
 

TheouAegis

Member
If i'm reading the original code right, gravity is 17/256. Set a variable jumping to 1. Set falling to 0. Set hover to 0. Jump, add gravity to the speed. When the speed is less than 0, set hover to 4. When hover is greater than 0, count it down. When hover is 0, set falling.

Code:
//Create Event//
jumping=0;
falling=0;
hover=0;
grav = 17/256;

//Step Event//
if jump_pressed
{
    if !jumping && !on_ladder && !carrying
    {
        vspeed = -1;
        jumping = 1;
    }
}
if hover
{
    if !(--hover) falling = 1;
}
if jumping
{
    vspeed += grav;
    if vspeed < 0
    {
        vspeed = 0;
        jumping = 0;
        hover = 4;
    }
}
if falling
{
    vspeed += grav;
    if /*your collision code here*/
    {
        vspeed = 0;
        falling = 0;
    }
}
 
M

MintyPretzel126

Guest
Maybe you should use states. So when your player is in the air, he cant move.
Code:
if (state != state_fall){
//move right or left
}
also, maybe you can make your own gravity variable.
There are lots of tutorials online that show you how.

When falling from a height I think you should use alarms. If you are not standing on ground, alarm[0] is set to a second. If the alarm runs out, you die, but if you hit the ground before a second, alarm[0] is shut down.
If i'm reading the original code right, gravity is 17/256. Set a variable jumping to 1. Set falling to 0. Set hover to 0. Jump, add gravity to the speed. When the speed is less than 0, set hover to 4. When hover is greater than 0, count it down. When hover is 0, set falling.

Code:
//Create Event//
jumping=0;
falling=0;
hover=0;
grav = 17/256;

//Step Event//
if jump_pressed
{
    if !jumping && !on_ladder && !carrying
    {
        vspeed = -1;
        jumping = 1;
    }
}
if hover
{
    if !(--hover) falling = 1;
}
if jumping
{
    vspeed += grav;
    if vspeed < 0
    {
        vspeed = 0;
        jumping = 0;
        hover = 4;
    }
}
if falling
{
    vspeed += grav;
    if /*your collision code here*/
    {
        vspeed = 0;
        falling = 0;
    }
}
Thanks for replying guys. :) So both of your scripts got me what I wanted, but there's still the problem with pressing left or right making the character hover. I haven't looked through much of basic movement programming, so I'm going to search that up.
 

TheouAegis

Member
the player hovers naturally in my code (or he should, if I read the code right). The left/right hovering is just seeing motion during the hovering. I have to go to work. I may play through DK tonight when I get home and see if I notice anything.
 
Top