Jump to content

Vehicle Sounds adjustment RPM


Ryosuke

Recommended Posts

  1.  
  2. Hi, I really need some help! To adjust the speed of sound with the RPM of the vehicle, can anyone help me?
  3.  
  4. local sound = {}
  5. function updateEngineSound() 
  6.     local allVehicles = getElementsByType("vehicle") 
  7.     for index, veh in ipairs (allVehicles) do 
  8.         local model = getElementModel(veh) 
  9.         if model == 411 then 
  10.             if getVehicleEngineState(veh) then 
  11.                 if isElement(sound[veh]) then 
  12.                     local gear = getVehicleCurrentGear ( veh ) or 1
  13.                     local velocityX, velocityY, velocityZ = getElementVelocity(veh) 
  14.                     local actualspeed = ((velocityX^2 + velocityY^2 + velocityZ^2)^(0.5)) * ((11 - gear) /10)
  15.                     local mph = actualspeed * 70 * 111.847 
  16.                     local minSoundSpeed = 0.15 
  17.                     local soundSpeed = mph/(1000+1000/minSoundSpeed) + minSoundSpeed  
  18.                     setSoundSpeed (sound[veh], soundSpeed) 
  19.                 else
  20.                     local x, y, z = getElementPosition(veh)
  21.                     sound[veh] = playSound3D("sounds/engine.wav", x, y, z, true)
  22.                     attachElements(sound[veh], veh)
  23.                 end 
  24.             else
  25.                 if isElement(sound[veh]) then
  26.                     destroyElement(sound[veh])
  27.                 end
  28.             end
  29.         end 
  30.     end 
  31. end 
  32. addEventHandler("onClientPreRender", root, updateEngineSound) 
Edited by Elvis wilian
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...