A dash that lasts a number of frames covers a different distance at every frame rate, and a dash on a timer goes too far on its last frame. In our Godot 4.7 test a dash meant to cover 6 m in 0.2 s went 12 m at 30 fps and 1.5 m at 240 fps when it lasted 12 frames. On a timer it went 6.5 m at 60 fps, 7 m at 30 fps, and 7 m at 60 fps when one frame took 0.1 s. Moving the last frame only for the time that was left gave 6.00 m in every case.
The code
Save it as dash_move.gd, keep one in your player script with var dash := preload("res://dash_move.gd").new(), start it with dash.start(-global_transform.basis.z, 6.0, 0.2) (direction, metres, seconds) and every physics frame call if dash.is_dashing(): move_and_collide(dash.step(delta)). With move_and_slide(), set velocity = dash.step(delta) / delta instead. It works the same with Vector2 positions in 2D.
extends RefCounted
## A dash that covers the same distance in the same time at any frame rate,
## and through a stutter. Works with Vector3 and Vector2.
## var dash := DashMove.new()
## dash.start(-global_transform.basis.z, 6.0, 0.2) # direction, metres, seconds
## # then every frame, in _physics_process or _process:
## if dash.is_dashing():
## move_and_collide(dash.step(delta))
## For a CharacterBody that uses move_and_slide, set velocity = dash.step(delta) / delta.
var _dir = Vector3.ZERO
var _speed := 0.0
var _left := 0.0
func start(direction, distance: float, duration: float) -> void:
_dir = direction.normalized()
_speed = distance / duration
_left = duration
func is_dashing() -> bool:
return _left > 0.0
func step(delta: float): # how far to move this frame
var dt := minf(delta, _left) # the last frame only moves for the time that was left
if dt <= 0.0:
return _dir * 0.0
_left -= dt
return _dir * (_speed * dt)
What we measured
A dash meant to cover 6 m in 0.2 s (30 m/s), run at five frame rates and once at 60 fps with a single 0.1 s frame, the kind of hitch a loading spike causes. Two runs gave the same numbers.
- Dash for 12 frames, moving speed times delta each frame: 12.00 m at 30 fps, 6.00 m at 60, 3.00 m at 120, 2.50 m at 144 and 1.50 m at 240. With the 0.1 s frame: 8.50 m.
- Dash on a timer, counting 0.2 s down after each move: 7.00 m at 30 fps, 6.50 m at 60, 6.25 m at 120, 6.04 m at 144 and 6.00 m at 240. With the 0.1 s frame: 7.00 m.
- The script: 6.00 m at every frame rate and with the 0.1 s frame, and nothing more once it has ended. In 2D, 240 px over 0.15 s at 144 fps came to 240.00 px.
Why it happens
Counting frames ties the dash to the frame rate: 12 frames is 0.4 s at 30 fps and 0.05 s at 240, so the same speed covers 8 times the distance. A timer fixes the length, but the frame that crosses the end still moves for its whole delta, past the moment the dash should have stopped. Even at 30 and 60 fps, where 0.2 s divides evenly, counting down 1/30 or 1/60 at a time leaves a tiny remainder above zero in floating point, so the timer ran one frame too many. The script clamps the last step to the time that was left, so the distance is speed times duration, whatever the frames are.
What to change
- A dash that should feel the same on every machine also needs its cooldown to hold at any frame rate: a fire rate that holds at any frame rate. Fast movement that skips through thin walls: a ball that hits the net however hard it is kicked.
- Dust under the feet while running: running dust on a CharacterBody3D. A different puff for grass, sand or snow: footsteps by ground surface.
What the dash looks like: Movement VFX for Godot 4 has 31 ready-made movement effects, including Dash Ground, Dash Air, Sprint Wind, landing dust and footsteps, in Modern and PSX looks. Call play() on Dash Ground when the dash starts.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Movement VFX for Godot 4 has 31 ready-made movement effects, including Dash Ground, Dash Air, Sprint Wind, landing dust and footsteps, in Modern and PSX looks.
More how-tos for Movement VFX for Godot 4: Running dust and landing puffs · Footstep particles that match the ground
More how-tos: Game feel
- A swing that settles the same at any frame rate
- Screen shake that returns to center
- 3D camera shake that lands back on center
- Hit stop and slow motion
- Confetti particles with random colors
- Choppy particles: fixed_fps and interpolate
- Play animations in 12 steps a second, at the right speed on any screen
- Keep a smooth follow camera, but jump with the player when they teleport
- Make a harvested crop pop out in an arc
- Shake a rock or tree when hit, without it drifting
- Pickups that fly to the player in the same time at any frame rate
- A cooldown that waits while the game is paused
- Keep attack presses made just before the swing ends
- A hold-to-craft bar that takes the same time at any frame rate and finishes once