Legacy GM Crouching not working

Liam Earles

Member
So, I've been making this game where I would like the player to crouch. My problem is, when I made a separate object for the crouch character, it seems like even though I hold down it would revert back to the idle position of the character. If I did something like, "press down to change to the crouch sprite", he would stay down. But when I add the "down release" event, it would still go back to the idle position. Can somebody help me? Is there something wrong I'm doing? I will post screenshots if you want, but I just can't seem to get the crouching mechanic right. Thanks if you have any feedback!

Also, I'm using drag and drop for this entire mechanic, and I was using code, but it was still the same.
 

YoSniper

Member
Posting screenshots would certainly be helpful. Personally, I would have made it so that your player simply changes its sprite (and collision mask if needed) during its crouch state.

You can do this by assigning the variable sprite_index. It might avoid some of this complicated object changing logic.
 

pipebkOT

Member
yeah, instead of switching objects for the crouching character and the idle, just don't do that.

just change the sprite_index of the player to the crouch sprite.
and make sure that the idle sprite and the crouching sprite have the same pixels size and origin point


switching objects for each action, example jumping , atacking, crouching, idle, is a bad practice
and should not be used.
instead just change the sprite_index of the object when you perfom an action,


example

space key pressed event

Code:
vspeed=-10        /// or the speed that you use for jumping this is just an example
sprite_index=sprite_player_jump

down key pressed

Code:
sprite_index=sprite_player_crouch
image_speed=0.3
down key released
Code:
sprite_index=sprite_player_idle
image_speed=0.3
Z key pressed event

Code:
sprite_index=sprite_player_punch
global.state="punch"
image_speed=0.3
for the punch part, you need to port the object_player_punch code to the obj_player and take in count this new global.state="punch" variable

and have an animation end event which is usefull for changing the sprite after the punching animation

animation end event

Code:
if sprite_index=sprite_player_punch
{
sprite_index=sprite_player_idle
global.state="idle"
}

and a collision with the floor event


Code:
gravity=0
vspeed=0
sprite_index=sprite_player_idle

all this sprites names are just examples, replace it with your own sprites names


also make sure that there aren't other events interfering with the sprite like the step event.
 
Last edited:

Liam Earles

Member
I only put the "key down press" and "key down release" codes, and it seems like when I only have the "key press down" event. the crouching works, but with the "key released down" event, the crouching does not want to work. Every time I put the "release down" event, it ruins it!
 

pipebkOT

Member
the same happened to me,

make sure that in the collision with the floor event, have the changing sprite code at the LAST part,

like this:

Code:
gravity=0
vspeed=0
sprite_index=sprite_player_idle

NOT like this

Code:
sprite_index=sprite_player_idle
gravity=0
vspeed=0
 

Liam Earles

Member
Okay, I was tinkering with the game, and there was an object that made the game release the dow arrow key. I deleted a piece of that code and the crouching works now! So I got it fixed!
 
Top