Ok. In this topic I want to make the gear change is smooth like from gear 1 to gear 2
this is my script:
local CurrentPitch = math.abs(carPrim.Velocity.Magnitude)
if carPrim.Velocity.Magnitude > 1 then
seatPart.Idle.Pitch = 0.75 + CurrentPitch/gear.Gear1
end
if carPrim.Velocity.Magnitude > 100 then
seatPart.Idle.Pitch = 0.7 + CurrentPitch/gear.Gear2
end
if carPrim.Velocity.Magnitude > 200 then
seatPart.Idle.Pitch = 0.7 + CurrentPitch/gear.Gear3
end
if carPrim.Velocity.Magnitude > 300 then
seatPart.Idle.Pitch = 0.7 + CurrentPitch/gear.Gear4
end
if carPrim.Velocity.Magnitude > 400 then
seatPart.Idle.Pitch = 0.7 + CurrentPitch/gear.Gear5
end
This isn’t the full script btw
CarPrim = car chassis (or base, for short)
seatPart = vehicleSeat that the humanoid is seatPart to
The engine sound (idle) is inside the seatPart
So the issue (I assume) is that the change in pitch is too sudden. The easiest way to deal with this is to use “lerping” (linear interpolation) to ease towards the desired value.
For example, the following code running every frame:
if velocity > 0 then
pitch = 1
else
pitch = 0
end
Can be made more gradual by using lerping:
local target_pitch
-- ...
if velocity > 0 then
target_pitch = 1
else
target_pitch = 0
end
pitch = Lerp(pitch, target_pitch, 0.1)
Lerp can be defined as follows:
function Lerp(A : number, B : number, T : number) : number
return A * (1 - T) + B * T
end