Godot gdscript works delayed with simple character control template

Godot 4 gdscript works delayed with simple character control template

In Godot, I coded movement codes for the platform game in gdscript, but it detects jumping etc. late, what could be the reason for this?

extends CharacterBody2D
const SPEED = 200.0
const JUMP_VELOCITY = -300.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

@onready var animator = get_node("AnimationPlayer")

func _physics_process(delta):
	if not is_on_floor():
		velocity.y += gravity * delta

	if Input.is_action_just_pressed("zipla") and is_on_floor():
		velocity.y = JUMP_VELOCITY
		animator.play("Jump")


	var direction = Input.get_axis("sol", "sag")
	if direction == -1:
		get_node("AnimatedSprite2D").flip_h=true
	elif direction == 1:
		get_node("AnimatedSprite2D").flip_h=false
	if direction:
		velocity.x = direction * SPEED
		if velocity.y == 0:
			animator.play("Run")
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		animator.play("Idle")
	if velocity.y>0:
		animator.play("Fall")
	move_and_slide()

Try running the physics on a separate thread in project settings.
image

1 Like

jumping still works with a delay

I tested your code and i don’t see any delay in the jump, try create a new project to see if is any setting you changed in project settings.

It could be because of the “CollisionShape2D”

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