Every time I use Sound.TimePosition for my vehicle engine sound, it always glitches as my vehicle accelerates

I have been currently working on an Electric Train with an AC Motor called “M7” and what I want to do is to make the train propulsion sound as realistic as possible by using Sound.TimePostion, but the problem is that the train propulsion keeps glitching when the train accelerates.


Here is how the sound was supposed to sound like

I’ve tried using NumberValues to reduce the glitches and I used Playback speed in my script as well but none of that worked.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

while true do
wait(0.05)
if script.Parent.AssemblyLinearVelocity.Magnitude > 0.1 then
if script.Parent.Engine.IsPlaying == false then
    script.Parent.Engine:Play()
end
script.Parent.Engine.TimePosition = 0.1 + script.Parent.Velocity.Magnitude/2.3
else
script.Parent.Engine:Stop()
end
end

So it looks like you’re trying to create an effect where the engine sound accelerates based on how fast the model is going. Is this correct?

If that is the case, you’re getting choppy audio because with the current code you have set up, you are jumping around the duration of the sound in a choppy manner. Typically to create the effect of a sound “accelerating” with the velocity of its model, you would have a looped sound which is a constant hum/buzz, then modify the Pitch property of the sound based on velocity.

1 Like

yeah but when I use that it sounds un-realistic

Real-life version

Sounds to me like you have three main issues. The first is that you are scaling the pitch too quickly. The second is that it sounds like your source audio has a pitch variation as well. And the third (and frankly most important) is that you are using a copyrighted audio recording.

3 Likes

I tried fixing that problem by removing the “0.1 +” from my script:

while true do
wait(0.05)
if script.Parent.AssemblyLinearVelocity.Magnitude > 0.1 then
if script.Parent.Engine.IsPlaying == false then
    script.Parent.Engine:Play()
end
script.Parent.Engine.TimePosition = script.Parent.Velocity.Magnitude/2.3
else
script.Parent.Engine:Stop()
end
end

but the audio still sounded glitchy and stuttery, but less severe.

You could try using SoundGroups combined with PitchShift effect to change the pitch.

If it still sounds glitchy try adding tiny 0.05 seconds between each change.

Audio on itself is a signal composed of many samples that are played one after another to create the vibrations that sound like music/audio effect to you.

If you suddenly change the pitch rapidly or try to do any sorts of audio processing real time you get audio artifacts.
Usually audio is slightly delayed and samples are cached so they can be processed a few microseconds before they are actually played/heard.

However, Roblox is pretty limited with what you can do with audio.
Roblox is not a engine where you can read/write/process each and every individual sample of an audio.

What I do is play audio normally, assign it to a SoundGroup and put a PitchShift inside the soundgroup.
SoundGroup allows you to apply real time audio processing to audio in a way.

If you interpolate (no TweenService) the PitchShift property with tiny 0.05 second delays you should be able to change the pitch without too much sound artifacts/glitches.

Don’t use TimePosition because what you’re doing is literally moving the actual place where audio starts playing giving this glitchy effect.

1 Like

It only worked 85% because I still hear glitchy sounds,

2 Likes