Lerp postion based off Time.get_ticks_usec() results in jittery movement

Godot Version

4.2

Question

Hello, I am making a rhythm game where notes fall down based on song position.
I am using Time.get_ticks_usec() to get the song position as per Sync the gameplay with audio and music — Godot Engine (stable) documentation in English

However when I do this the change in position for the notes is sometimes inconsistent with the delta time according to both get_ticks and process, I’d say it’s around 60% of the time I open a level in the game the notes are jittery


image
image

Here is what the stuttering looks like

This happens regardless of fps, resolution, or vsync toggle, and is uncorrelated with frame drops, although it is slightly better with higher fps

I have tried using both the cpu and visual profiler and have found nothing correlating with the stuttering.

Here is the code I used for incrementing song position

songPosition = songOffset + (Time.get_ticks_usec() - timeStart) / 1000000.0 + GlobalSettings.audioOffset/1000 - timeDelay
#timeDelay is set once at start of song and is equal to
AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()

And code for scrolling notes

position = lerp(startPos, endPos, (manager.conductor.songPosition + GlobalSettings.visualOffset/1000 - startTime)/duration)

Both lines of code are run in the _process method but the jittering still happens whether or not it is in _physics process or _process.

Is there anything I could possibly be missing here?

You need to do the lerp the physics_process function

I see that your position update does not depend on delta also, which is probably why you have jittering as your motion will be dependant on framerate instead of being independant of framerate. try something like this instead in physics process:

## Perform the interpolation
var interpolatedPosition = lerp(startPos, endPos, (manager.conductor.songPosition + GlobalSettings.visualOffset/1000 - startTime)/duration)

## Update position based on delta for smooth movement
position += (interpolatedPosition - position) * delta
1 Like

This doesn’t result in in the correct movement as the lerp calculates the absolute position and not the delta position. And still produces a jittery movement despite it including delta in the equation now.

I’ve also mentioned that placing the code in _physics_process() does not fix the issue.

Both lines of code are run in the _process method but the jittering still happens whether or not it is in _physics process or _process.

I’ve also tried to base the song position off delta in process and physics process but that resulted in a more jittery result even when changing the physics process tick rate to a higher number .