← Pixel Dreamer Studio

Pickups that fly to the player in the same time at any frame rate

Make the lerp weight depend on delta: 1 - exp(-sharpness * delta).

Use 1.0 - exp(-sharpness * delta) as the weight of the lerp instead of a fixed number like 0.1. A fixed weight closes the same share of the gap every frame, so more frames a second means a faster pull. In our Godot 4.7 test a coin 4 m from the player took 0.967 s to be collected at 30 fps, 0.483 s at 60 fps and 0.201 s at 144 fps. With the script below it took 0.500 s at all three.

The code

Attach this to the pickup and set target to the player. Once the player is inside pull_radius, the pickup flies in, sends collected when it is within 0.2 m and removes itself. Connect collected to add the coin and play the collect effect.

extends Node3D
## Pulls a pickup (coin, gem, heart) to the player once it is close, in the same time at any frame rate.
## Attach it to the pickup and set target to the player, or to a Node3D at the player's chest.

signal collected

@export var target: Node3D
@export var pull_radius := 4.0
@export var sharpness := 6.0  ## how fast it closes the gap: 6 takes about half a second from 4 m


func _physics_process(delta: float) -> void:
	if target == null:
		return
	var goal := target.global_position
	if global_position.distance_to(goal) > pull_radius:
		return
	# the share of the gap closed this frame grows with delta, so 1 long frame = 2 short ones
	global_position = global_position.lerp(goal, 1.0 - exp(-sharpness * delta))
	if global_position.distance_to(goal) < 0.2:
		collected.emit()
		queue_free()

What we measured

A pickup 4 m from the player. We stepped the physics ourselves at a fixed frame rate and counted how long it took to come within 0.2 m. Two runs gave the same numbers.

Why a fixed weight depends on the frame rate

lerp(a, b, 0.1) moves 10% of the way each time it runs. At 144 fps it runs almost 5 times as often as at 30 fps, so the pickup arrives almost 5 times sooner. With 1.0 - exp(-sharpness * delta) two short frames close exactly as much of the gap as one long frame, so only the time passed counts. The same goes for a camera that follows the player or a health bar that slides to its new value.

What to change

Coins flying to a counter on the screen instead: coins fly to the HUD counter. The same by-time idea for a torch light: a flicker at the same speed at any frame rate.

Collect effects in a pixel art style: Pixel Art 3D VFX for Godot 4 has 40 effects with a 4-color palette and dithering, including Coin Collect, Collect Star Burst, Item Glow, Level Up, Heal, Teleport, portals, campfires and explosions.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Pixel Art 3D VFX for Godot 4 has 40 pixel art effects for 3D games, including Coin Collect, Collect Star Burst, Item Glow, Level Up and Teleport.

More how-tos for Pixel Art 3D VFX for Godot 4: A torch light that flickers the same on every screen

More how-tos: Game feel