Why is this 2D movement not framerate independent?

Godot Version



I have a top-down 2D character controller with some simple acceleration. I coded this with physics/common/physics_ticks_per_second set to 60, but when setting it to 144 for my 144hz monitor, the character now moves significantly slower.

Am I not multiplying by delta correctly? Is there something I should be doing differently to take advantage of HFR monitors?

const MAX_SPEED:float = 20000
const START_SPEED:float = 8000
const ACC:float = 3000
const DEACC:float = 2000

var speed:float = 0

func _physics_process(delta):
	var input:Vector2 = Vector2.ZERO
	var xdirection:float = Input.get_axis("move_left", "move_right")
	var ydirection:float = Input.get_axis("move_up","move_down")
	input.x = xdirection
	input.y = ydirection
	if !input.x and !input.y:
		speed = START_SPEED
		velocity = velocity.move_toward(Vector2.ZERO,DEACC*delta)
		speed += ACC * delta
		velocity += input.normalized() * speed * delta
		velocity = velocity.limit_length(MAX_SPEED * delta)
		facing = input.angle()
1 Like

Don’t multiply velocity by delta when using CharacterBody2D.move_and_slide() because the function will take care of that.


That’s it, thank you!

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