Skip to content

Commit

Permalink
Footsteps: Fix offset footstep and shallow water sound bugs
Browse files Browse the repository at this point in the history
Fix footstep sounds coming from nodes to either side when walking on a
1 node wide row of nodebox slabs such as default:snow.
Fix sand footsteps when swimming in 1 node deep water.

Use a new function 'getFootstepNodePos()' instead of 'getStandingNodePos()'
to avoid using a horizontally-offset 'sneak node' for sounds.

Sound is selected from the node BS * 0.05 below the player's feet, so
that 1/16th slabs will play the slab sound but 1/32nd slabs will not.
If the player is not 'touching ground' the node detection position is
changed to BS * 0.5 below to preserve footstep sounds when landing after
a jump or fall.
  • Loading branch information
paramat committed Feb 12, 2017
1 parent 1de08e1 commit 984e063
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3530,7 +3530,7 @@ void Game::updateSound(f32 dtime)
LocalPlayer *player = client->getEnv().getLocalPlayer();

ClientMap &map = client->getEnv().getClientMap();
MapNode n = map.getNodeNoEx(player->getStandingNodePos());
MapNode n = map.getNodeNoEx(player->getFootstepNodePos());
soundmaker->m_player_step_sound = nodedef_manager->get(n).sound_footstep;
}

Expand Down
12 changes: 12 additions & 0 deletions src/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,18 @@ v3s16 LocalPlayer::getStandingNodePos()
return floatToInt(getPosition() - v3f(0, BS, 0), BS);
}

v3s16 LocalPlayer::getFootstepNodePos()
{
if (touching_ground)
// BS * 0.05 below the player's feet ensures a 1/16th height
// nodebox is detected instead of the node below it.
return floatToInt(getPosition() - v3f(0, BS * 0.05f, 0), BS);
// A larger distance below is necessary for a footstep sound
// when landing after a jump or fall. BS * 0.5 ensures water
// sounds when swimming in 1 node deep water.
return floatToInt(getPosition() - v3f(0, BS * 0.5f, 0), BS);
}

v3s16 LocalPlayer::getLightPosition() const
{
return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);
Expand Down
1 change: 1 addition & 0 deletions src/localplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LocalPlayer : public Player
void applyControl(float dtime);

v3s16 getStandingNodePos();
v3s16 getFootstepNodePos();

// Used to check if anything changed and prevent sending packets if not
v3f last_position;
Expand Down

0 comments on commit 984e063

Please sign in to comment.