• 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!

[Solved] How do I add footstep sounds to my player?

pixeltroid

Member
So I've been tinkering around with audio since yesterday and so far its been pretty easy to get a sound effect to play whenever a single event happens, like a death or a projectile creation.

I have been trying to create the sound of footsteps for my player. My audio file is that of a single footstep sound. So far I have managed to create the sound of a single footstep whenever the player lands on the ground, after jumps or falling. I did this by adding audio_sound_play(sfx_footstep,8,false) in players collision event with the ground object (obj_solid). This works pretty decently. But what I would really like is to have the footstep audio loop whenever he moves on the ground, but I haven't been able to achieve that.

I tried adding the same code to my left/right movement code, but the sound messes up by playing over itself and also by playing whenever the player jumps left or right.

I need the sound to:
a. play only whenever player is moving left/right on the ground.
b. Stop whenever he reaches a wall
c. Stop whenever he jumps

Any idea how I could achieve this?

Below is my players movement script:

Code:
{
//moving left right
if keyboard_check(ord("D")) && place_free(x+4,y) && !keyboard_check(ord("A")) {
if (place_free(x,y+1)) {
if (place_free(x+4,y+vspeed)) {
sprite_index = spr_playerwalk;

image_speed = .3;
image_xscale = 2;
//facing="right";; //moving right
x+=4;
}
} else {
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = 2;
x+=4;
//facing="right";; //moving right
}
} else if keyboard_check(ord("A")) && place_free(x-4,y) && !keyboard_check(ord("D")) {
if (place_free(x,y+1)) {
if (place_free(x-4,y+vspeed)) {
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = -2;
x-=4;
//facing ="left"; //facing left
}
} else {
x-=4;
//facing ="left"; //facing left
sprite_index = spr_playerwalk;
image_speed = .3;
image_xscale = -2;
}
} else {
sprite_index = spr_playerstand;
image_speed = .1

}

if (!place_free(x,y+1)) {

//jumping
if keyboard_check_pressed(ord('W')) {
vspeed = -10;
}
} else {
sprite_index = spr_playerjump;
}

if (!place_free(x,y+1)) {


}
}
Any help would be appreciated!
 

jo-thijs

Member
To make the sound loop, change this:
Code:
audio_sound_play(sfx_footstep,8,false)
to this:
Code:
audio_sound_play(sfx_footstep,8,true)
 

pixeltroid

Member
To make the sound loop, change this:
Code:
audio_sound_play(sfx_footstep,8,false)
to this:
Code:
audio_sound_play(sfx_footstep,8,true)
Hi. Thanks for your input. I earlier tried making it "true" and having the sound loop but it did not work. It just caused a weird buzzing sound of the footsteps playing over itself. Even when player was jumping.

But someone on reddit adviced me to make footstep sound play whenever the players sprite is in his "walk animation". He solved my problem.

https://www.reddit.com/r/gamemaker/...dd_footsteps_to_my_player_as_he_walks/d6z6exk
 

pixeltroid

Member
Top