There is an error in the mob code and I don't understand how to fix it

extends CharacterBody2D

var chase = false
var speed = 100

func _physics_process(delta: float) -> void:

	# Add the gravity.
	if not is_on_floor():
		velocity += get_gravity() * delta
	var player = $"../../player/player1"
	var direction = (player.position - self.position).normalaized
	if chase == true:
		velocity.x =direction.x
	move_and_slide()


func _on_detector_body_entered(body: Node2D) -> void:
	if body.name == "player"
		chase = true

* List item

I wrote some code for a mob to attack the player when he enters its area of ​​effect, but the code doesn’t work.

Hello there! Is there any error in the Godot console when you run the game?

In this line there’s a typo

The correct function to normalize a vector is .normalized(). That line should be:

var direction = (player.position - self.position).normalized()
2 Likes

yes, an error appears in the console (19, 21)

This line will cause an error because there’s no “:” at the end. The correct syntax for an if statement is:

if condition:

The error should be resolved with the colon.

1 Like