Legacy GM make player duck with sprite_index

  • Thread starter SonicTheHedgehog+123
  • Start date
S

SonicTheHedgehog+123

Guest
Hello everyone
I want my player to duck if the button "D" is presse. It should use the sprite duck and if the player is in the duck
state he cant go left or right or jump. Also when the player is in the air and ducks he falls down.
My problem is that when the player goes from the duck to the normal sprite he cant switch to other sprites unless the duck button is pressed this is bad because I have items in my game and the player should switch to other sprites if he collides with the Item .This function doesnt work anymore because the player will take always the 1. sprite if the player is not ducking. Is there a possibility to solve this problem with variables or is there a better way. However this is a complicated task I would be very happy I get help:p

Step Event:

if keyboard_check(ord("S"))
{
sprite_index = Ducken
}
else
{
sprite_index = Fledermaus_Bild
}
if sprite_index = Ducken
{
hspeed = 0;
vspeed = 0;
}
 
Last edited by a moderator:

TsukaYuriko

☄️
Forum Staff
Moderator
Without seeing any of your code, all we can do is give you general pointers. Unless this will be sufficient for your needs, please post all code relevant to the player, ducking and changing states.
 
S

SonicTheHedgehog+123

Guest
ok got it here you have my chaos emeralds:

Step Event:

if keyboard_check(ord("S"))
{
sprite_index = Ducken
}
else
{
sprite_index = Fledermaus_Bild
}
if sprite_index = Ducken
{
hspeed = 0;
vspeed = 0;
}
 
S

SonicTheHedgehog+123

Guest
Do you mean the player collide with item code:

PowerUp:

Collision Event with Object Player:

with (Fledermaus)
{
room_speed = 30;
sprite_index = Fledermaus_PowerUp;
image_speed = 1/3;
alarm[4] = 300;
}
instance_destroy()


The code is pretty much the same with the other Power Ups but here you also have the sprite_index of the other power ups:
PowerUp_Bild
PowerUp2_Bild
PowerUp3_Bild

Its works partially.

works:
-switches to the duck sprite and back to the player sprite
-if the player is ducking he cant move left or right
-if the player is ducking in the air he falls down

problems:
-if the player goes from duck to standing position then the player sprite gets stuck in the wall.Then i must jump to free my player. (solved)
-the player shouldnt be able to jump when in duck position.(solved with code below)
if sprite_index = !Ducken{
if keyboard_check_pressed(ord("W"))
jumpbuffer = 9;
}

-if the player goes from duck to normal position and then picks up an Item the item image doesnt switch(because of the step event).
 
Last edited by a moderator:
Hard to figure this out for you but can I suggest you check all your player sprites for each state and make sure each origin is the same and each collision mask is the same in terms of positioning and dimension.

If one of your sprites is say bottom right instead of bottom left, or say the collision mask is a few pixels higher/lower than the others this could explain why your player is getting stuck in between sprite changes.
 
S

SonicTheHedgehog+123

Guest
Yes my sprites orgins were in the center. I did put the center of the duck image higher. Know it does work.
Thank you very much Lance KLepp. I own you one.
Know only 2 problems to solve
 
Top