Crash sounds based on speed and direction (#2964)
* Small clarification to prevent build errors Building outside of this directory prevents the executable from launching, this small addition can help prevent this issue from happening. * Initial calculation and application However this doesn't handle other karts well. Max speed both karts should differ in each direction * Properly scale volume appropriate to speed and direction * Improve clarity in variables and created getcurrentemitter method * equation is awful, don't use * Head on collision fix physics to be more accurate * Removed debug std cout * Cleaned up method for calculating volume, other misc fixes Changed from m_body->getlinearvelocity() to getvelocity() to ensure that the reader doesn't mistake the functions as being different * Fixed wrong value for min_volume * Updated to Styling guidelines * Fixed tabs to spaces * fixed tab to space * Coding conventions, fix set volume * Last tab fix * Make quiter sounds louder through math, whilst ensuring not imaginary numbers
This commit is contained in:
@@ -2177,19 +2177,46 @@ void Kart::playCrashSFX(const Material* m, AbstractKart *k)
|
||||
// karts from bouncing back, they will instead stuck towards the obstable).
|
||||
if(m_bounce_back_time<=0.0f)
|
||||
{
|
||||
if (m_body->getLinearVelocity().length()> 0.555f)
|
||||
if (getVelocity().length()> 0.555f)
|
||||
{
|
||||
const float speed_for_max_volume = 15; //The speed at which the sound plays at maximum volume
|
||||
const float max_volume = 1; //The maximum volume a sound is played at
|
||||
const float min_volume = 0.2; //The minimum volume a sound is played at
|
||||
|
||||
float volume; //The volume the crash sound will be played at
|
||||
|
||||
if (k == NULL) //Collision with wall
|
||||
{
|
||||
volume = sqrt( abs(m_speed / speed_for_max_volume));
|
||||
}
|
||||
else
|
||||
{
|
||||
const Vec3 ThisKartVelocity = getVelocity();
|
||||
const Vec3 OtherKartVelocity = k->getVelocity();
|
||||
const Vec3 VelocityDifference = ThisKartVelocity - OtherKartVelocity;
|
||||
const float LengthOfDifference = VelocityDifference.length();
|
||||
|
||||
volume = sqrt( abs(LengthOfDifference / speed_for_max_volume));
|
||||
}
|
||||
|
||||
if (volume > max_volume) { volume = max_volume; }
|
||||
else if (volume < min_volume) { volume = min_volume; }
|
||||
|
||||
SFXBase* crash_sound_emitter = getNextEmitter();
|
||||
crash_sound_emitter->setVolume(volume);
|
||||
|
||||
// In case that the sfx is longer than 0.5 seconds, only play it if
|
||||
// it's not already playing.
|
||||
if (isShielded() || (k != NULL && k->isShielded()))
|
||||
{
|
||||
getNextEmitter()->play(getXYZ(), m_boing_sound);
|
||||
crash_sound_emitter->play(getXYZ(), m_boing_sound);
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = rand() % CRASH_SOUND_COUNT;
|
||||
|
||||
SFXBuffer* buffer = m_crash_sounds[idx];
|
||||
getNextEmitter()->play(getXYZ(), buffer);
|
||||
crash_sound_emitter->play(getXYZ(), buffer);
|
||||
}
|
||||
} // if lin_vel > 0.555
|
||||
} // if m_bounce_back_time <= 0
|
||||
|
||||
Reference in New Issue
Block a user