Skip to content

Commit 984e063

Browse files
committedFeb 12, 2017
Footsteps: Fix offset footstep and shallow water sound bugs
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.
1 parent 1de08e1 commit 984e063

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

‎src/game.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3530,7 +3530,7 @@ void Game::updateSound(f32 dtime)
35303530
LocalPlayer *player = client->getEnv().getLocalPlayer();
35313531

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

‎src/localplayer.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,18 @@ v3s16 LocalPlayer::getStandingNodePos()
655655
return floatToInt(getPosition() - v3f(0, BS, 0), BS);
656656
}
657657

658+
v3s16 LocalPlayer::getFootstepNodePos()
659+
{
660+
if (touching_ground)
661+
// BS * 0.05 below the player's feet ensures a 1/16th height
662+
// nodebox is detected instead of the node below it.
663+
return floatToInt(getPosition() - v3f(0, BS * 0.05f, 0), BS);
664+
// A larger distance below is necessary for a footstep sound
665+
// when landing after a jump or fall. BS * 0.5 ensures water
666+
// sounds when swimming in 1 node deep water.
667+
return floatToInt(getPosition() - v3f(0, BS * 0.5f, 0), BS);
668+
}
669+
658670
v3s16 LocalPlayer::getLightPosition() const
659671
{
660672
return floatToInt(m_position + v3f(0,BS+BS/2,0), BS);

‎src/localplayer.h

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LocalPlayer : public Player
6868
void applyControl(float dtime);
6969

7070
v3s16 getStandingNodePos();
71+
v3s16 getFootstepNodePos();
7172

7273
// Used to check if anything changed and prevent sending packets if not
7374
v3f last_position;

0 commit comments

Comments
 (0)