Make vehicle crash sounds based on velocity changes

This commit is contained in:
tovjemam 2026-06-14 00:51:16 +02:00
parent 9c0a062e80
commit 31330b9cfe
2 changed files with 32 additions and 18 deletions

View File

@ -364,30 +364,43 @@ void game::Vehicle::UpdateCrash()
} }
else else
{ {
if (crash_intensity_ > 1000.0f) if (physics_)
{ {
float volume = RandomFloat(0.9f, 1.2f); auto bt_vel = physics_->GetBtBody().getLinearVelocity();
float pitch = RandomFloat(1.0f, 1.3f); glm::vec3 velocity(bt_vel.x(), bt_vel.y(), bt_vel.z());
float diff = glm::distance(velocity, prev_velocity_);
prev_velocity_ = velocity;
if (crash_intensity_ > 12000.0f) float snd_crash_intensity = glm::max(diff * 500.0f, crash_intensity_);
if (snd_crash_intensity > 1000.0f)
{ {
volume *= 1.7f; float volume = RandomFloat(0.9f, 1.2f);
pitch *= 0.8f; float pitch = RandomFloat(1.0f, 1.3f);
}
if (crash_intensity_ > 4000.0f) if (snd_crash_intensity > 12000.0f)
{ {
volume *= 1.3f; volume *= 1.7f;
pitch *= 0.8f; pitch *= 0.8f;
} }
else if (snd_crash_intensity > 4000.0f)
{ {
volume *= 0.8f; volume *= 1.3f;
pitch *= 1.2f; pitch *= 0.8f;
}
else
{
volume *= 0.8f;
pitch *= 1.2f;
}
PlaySound("crash", volume, pitch);
no_crash_frames_ = 8 + rand() % 5;
} }
PlaySound("crash", volume, pitch);
no_crash_frames_ = 7 + rand() % 10;
} }
} }
crash_intensity_ = 0.0f; crash_intensity_ = 0.0f;

View File

@ -134,6 +134,7 @@ private:
float crash_intensity_ = 0.0f; float crash_intensity_ = 0.0f;
size_t no_crash_frames_ = 0; size_t no_crash_frames_ = 0;
glm::vec3 prev_velocity_ = glm::vec3(0.0f);
std::unique_ptr<DeformGrid> deformgrid_; std::unique_ptr<DeformGrid> deformgrid_;