Mobs stopped walking after restarting the godot editor. I made the game according to the video tutorials. Everything was working fine before quitting the program. Today I continued making the game, but the mobs are no longer walking. The walking animation starts when I approach the mob, but the mob stands still. help please. The code is attached.
The moba code is below. I apologize for my inexperience, I’m just learning.
extends CharacterBody2D
Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
var chase = false
var speed = 100
var alive = true
@onready var anim = $AnimatedSprite2D
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
var player = $“…/…/Player/Player”
var diretion = (player.position - self.position).normalized()
if alive == true:
if chase == true:
velocity.x = diretion.x * speed
anim.play(“run”)
else:
velocity.x = 0
anim.play(“idle”)
if diretion.x < 0:
$AnimatedSprite2D.flip_h = true
else:
$AnimatedSprite2D.flip_h = false
func _on_area_2d_body_entered(body):
if body.name == “Player”:
chase = true
func _on_area_2d_body_exited(body):
if body.name == “Player”:
chase = false
func _on_area_2d_2_body_entered(body):
if body.name == “Player”:
body.velocity.y -= 300
death()
func _on_death_2_body_entered(body):
if body.name == “Player”:
if alive == true:
body.health -=40
death()
func death():
alive = false
anim.play(“death”)
await anim.animation_finished
queue_free()