• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Why does my player get stuck in the air?

J

JopRillos2001

Guest
Im making a platform game where my character can duck. When he ducks in the air, he performs a groundpound. key_duck is asigned to the 'S' key (not pressed or released). vsp is the vertical speed and duckgrav is the groundpound speed. While performing the groundpound, the sprite should be changed to a duck animation.

Here is the code I use:

if (key_duck) {
vsp = duckgrav;
sprite_index = spr_player_duck;
} else {
//other movement
}
When I try this, the player gets stuck in the air with a duck sprite while I press 'S'.
Once I release the key, the groundpound gets performed, but the sprite goes back to a normal fall animation.

When I tried to change key_duck to a pressed key event, the groundpound works, but without the correct animation (gets reset by default animation). This is the code for the fall and jump animation.

if(vsp < 0) {
image_index = 0;
} else {
image_index = 2;
}​
 

woods

Member
your jump/fall code
Code:
if(vsp < 0) {
image_index = 0;
} else {
image_index = 2;
}
translates to
if vsp >=0 image_index == 2

so if you are falling/groundpounding your image_index is 2
 
J

JopRillos2001

Guest
the jump fall code is part of //other movement in the else section.
 

woods

Member
either way, with your vsp over 0 gives sprite 2

is there anywhere else that has keyboard_check(ord("S")) ... or anywhere else that controls your vsp?
mind sharing your //other movement code? ;o)
 
I'm going to assume some thing about how you'd want this to occur:

If they have pressed the ground pound key, but then let go off it before impact, the "gravity" doesn't want to change. As that would look weird if they sped up falling through the "force" of ground pounding, and then slowed down to the normal falling gravity speed if the key is let go. Basically if activated at any point during falling - once their gravity speed goes up, it stays there until collision with the ground, regardless of whether the ground pound is finished or not. Sound sensible?

I haven't really looked at movement of this type, so this is probably pretty rough. I get an object moving up (a naff workaround for jumping) and then coming back down again (either because it reached the top height of the jump, or because the player intervened by pressing down). If the player presses down during "falling" it speeds up the gravity, and once sped up it stays that way - even if they let go of the key. If they are holding the key when the player hits an object called "ground_obj" it will do the ground pound (creating an instance of obj_dust for the purpose of showing it's worked here)

As I said before, this is pretty rough and probably not the best way / super efficient. But it worked for me, and may give you something to go on :)

create event:
Code:
has_activated_pound = false;
pound_is_active = false;
is_falling = false;
on_ground = true;
normal_gravity = 2;
duckgrav = 6;
start_y = 0;
did_jump = false;
step event:

Code:
if keyboard_check(ord("W"))
{
on_ground = false;
if !did_jump
{
start_y = y;
did_jump = true;
}
if !is_falling
{
vspeed = -2;
}
}


if did_jump 
{
if abs(y - start_y) > 80
{
vspeed = normal_gravity;
is_falling = true;
}
}


if keyboard_check(ord("S"))
{
did_jump = false;
if !on_ground
{
pound_is_active = true;
is_falling = true;
if !has_activated_pound
{
vspeed = duckgrav;
has_activated_pound = true;
}
sprite_index = spr_player_duck;
}
}
else
{
pound_is_active = false;
if is_falling
{
sprite_index = ??
}
}

if !has_activated_pound
{
if !on_ground
{
if is_falling
{
sprite_index = ?? // don't know what your normal sprite is called
vspeed = normal_gravity;
}
}
}
end step:
Code:
if is_falling
{
if place_meeting(x, y, ground_obj)
{
did_jump = false;
has_activated_pound = false;
vspeed = 0;
if pound_is_active
{
instance_create(x, bbox_bottom, obj_dust); // ignore this - it just shows me that this worked
}
on_ground = true;
is_falling = false;
}
}
 
Top