Godot Version
4.3.stable
Question
I upgraded my project from 4.2 to 4.3 in order to use physics interpolation (among other new features). Since doing so, my camera shake has stopped working. If I set the camera’s physics_interpolation_mode to off it works like before, but I figure I’d have it use physics interpolation if possible in order to reap its benefits (and because it causes an error somewhere else). Here’s the Camera2D’s code:
extends Camera2D
## How quickly to move through the noise
@export var noise_move_speed: float = 1.0
## Amount to mulitply the result from the noise by
@export var shake_strength: float = 30.0
## How fast the shake should wear off
@export var shake_decay: float = 2.0
var rand := RandomNumberGenerator.new()
var noise := FastNoiseLite.new()
# Used to keep track of where we are in the noise so that we can smoothly move through it
var noise_i := 0.0
var current_shake_strength := 0.0
func _ready() -> void:
rand.randomize()
# Randomize the generated noise
noise.seed = rand.randi()
# Period affects how quickly the noise changes values
noise.frequency = 1.0
func _physics_process(delta: float) -> void:
# Fade out shake over time
current_shake_strength = lerp(current_shake_strength, 0.0, shake_decay * delta)
# Shake created by adjusting camera offset
offset = get_noise_offset(delta)
prints("camera offset: ", offset)
func shake() -> void:
print("shake called")
current_shake_strength = shake_strength
func get_noise_offset(delta: float) -> Vector2:
noise_i += delta * shake_strength
return Vector2(
noise.get_noise_2d(1, noise_i) * current_shake_strength,
noise.get_noise_2d(100, noise_i) * current_shake_strength
)
and here’s a relevant sample from those print statements
camera offset: (0, 0)
camera offset: (0, 0)
camera offset: (0, 0)
camera offset: (0, 0)
camera offset: (0, 0)
camera offset: (0, 0)
shake called
camera offset: (-6.599189, 9.738193)
camera offset: (-11.40813, 2.594339)
camera offset: (3.911199, -7.701052)
camera offset: (10.73742, -16.0617)
camera offset: (-16.11313, 4.837891)
camera offset: (-12.49, -7.294363)
camera offset: (11.424, -0.743336)
It looks like the offset’s value is what it should be, but it isn’t reflected visually at all. Is there a way to get working camera shake with physics interpolation?