Make vehicle crash sounds based on velocity changes
This commit is contained in:
parent
9c0a062e80
commit
31330b9cfe
@ -364,17 +364,26 @@ void game::Vehicle::UpdateCrash()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (crash_intensity_ > 1000.0f)
|
if (physics_)
|
||||||
|
{
|
||||||
|
auto bt_vel = physics_->GetBtBody().getLinearVelocity();
|
||||||
|
glm::vec3 velocity(bt_vel.x(), bt_vel.y(), bt_vel.z());
|
||||||
|
float diff = glm::distance(velocity, prev_velocity_);
|
||||||
|
prev_velocity_ = velocity;
|
||||||
|
|
||||||
|
float snd_crash_intensity = glm::max(diff * 500.0f, crash_intensity_);
|
||||||
|
|
||||||
|
if (snd_crash_intensity > 1000.0f)
|
||||||
{
|
{
|
||||||
float volume = RandomFloat(0.9f, 1.2f);
|
float volume = RandomFloat(0.9f, 1.2f);
|
||||||
float pitch = RandomFloat(1.0f, 1.3f);
|
float pitch = RandomFloat(1.0f, 1.3f);
|
||||||
|
|
||||||
if (crash_intensity_ > 12000.0f)
|
if (snd_crash_intensity > 12000.0f)
|
||||||
{
|
{
|
||||||
volume *= 1.7f;
|
volume *= 1.7f;
|
||||||
pitch *= 0.8f;
|
pitch *= 0.8f;
|
||||||
}
|
}
|
||||||
if (crash_intensity_ > 4000.0f)
|
if (snd_crash_intensity > 4000.0f)
|
||||||
{
|
{
|
||||||
volume *= 1.3f;
|
volume *= 1.3f;
|
||||||
pitch *= 0.8f;
|
pitch *= 0.8f;
|
||||||
@ -386,8 +395,12 @@ void game::Vehicle::UpdateCrash()
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlaySound("crash", volume, pitch);
|
PlaySound("crash", volume, pitch);
|
||||||
no_crash_frames_ = 7 + rand() % 10;
|
no_crash_frames_ = 8 + rand() % 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crash_intensity_ = 0.0f;
|
crash_intensity_ = 0.0f;
|
||||||
|
|||||||
@ -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_;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user