Need help with physics interpolation

Godot Version

4.2.1

Question

I’m trying to implement physics interpolation into a 2d topdown to fix “frame stuttering / blur” in environment.
this seems to work really well although now the player can move through walls because the position is being modified. I’m not really sure where to go from here
I tried adding if !is_on_wall() but that only fixed it 50% of the time


func _process(delta): # calculate curve direction from velocity.angle instead
	var alpha = Engine.get_physics_interpolation_fraction() # interpolate movement
	smoothed_position = previous_position.lerp(current_position, alpha)
	global_position = smoothed_position # move the player in the idle process

	curve_and_jump()
	label_settings(delta)

func _physics_process(delta):
	previous_position = current_position # update previous position
	physics_movement(delta) # handles movement
	drift(delta) # handles drift
	custom_tile_data_getter() # gets custom tile data
	current_position = global_position # update current position
	current_position += velocity * delta # add velocity

	print(velocity)
	move_and_slide()

If you’re willing to upgrade your Godot version, the native physics interpolation has been implemented in 4.3 for 2D and 4.4 for 3D.

This should allow to handle the interpolation much easier and more reliable.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.