Enemy is moving slow towards Player in GODOT 4

I tried to follow heartbest tutorial and i made the enemy chasing system and everything works fine except the speed of the enemy. It detects and moves towards the player. However it moves veerryyy slow. Is there something im doing wrong in the script. And it only seems to happen in GODOT 4

extends CharacterBody2D

const EnemyDeathEffect = preload("res://scenes/enemy_death_effect.tscn")

@export var ACCELERATION = 300
@export var MAX_SPEED = 50
@export var FRICTION = 200

enum {
	IDLE,
	WANDER,
	CHASE
}

var state = CHASE



var knockback = Vector2.ZERO


@onready var sprite = $AnimatedSprite
@onready var stats = $Stats
@onready var playerDetectionZone = $PlayerDetectionZone

func _ready():
	print(stats.health)

func _physics_process(delta):
	knockback = knockback.move_toward(Vector2.ZERO, FRICTION * delta)
	set_velocity(knockback)
	move_and_slide()
	knockback = velocity
	
	
	match state:
		IDLE:
			velocity = velocity.move_toward(Vector2.ZERO, 200 * delta)
			seek_player()
	
		WANDER:
			pass
		
		CHASE:
			var player = playerDetectionZone.player #my player is called playerg
			if player != null:
				var direction = (player.global_position - global_position)/MAX_SPEED #.normalized()
				velocity = velocity.move_toward(direction * MAX_SPEED, ACCELERATION * delta)
				
				
				
				
			sprite.flip_h = velocity.x < 0


	move_and_slide()

func seek_player():
	if playerDetectionZone.can_see_player():
		state = CHASE


func _on_hurtbox_area_entered(area):
	stats.health -= area.Damage
	knockback = area.knockback_vector * 120
	#knockback = area.knockback_vector * 150


func _on_stats_no_health():
	queue_free()
	var enemyDeathEffect = EnemyDeathEffect.instantiate()
	get_parent().add_child(enemyDeathEffect)
	enemyDeathEffect.global_position = global_position
	enemyDeathEffect.offset.y = -15

were you porting from godot 3 to godot 4?

Yeah, I was I fixed the problem by increasing the number. I found out that multiplying by delta decreases the speed so the number had to be insanely high

from what i read from documentation, there’s no difference in delta value for physics process on 3.5 and 4.2
if it felt real slow, then yes try increase it

1 Like

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