HELP MY ENEMY IS A HAVING A STROKE!!!!

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Erto

Hi

I’m trying to make an enemy on my game using Rafa Fiedo video
Its working pretty well but i do have a problem. For some reason my enemy keeps going left and right without moving(just playig the animation. See the problem:https://www.youtube.com/watch?v=9a8S7xUbYj4][1]

Does anyone know where should I look for the problem? Because I’m lost. Is it in the code, layers, or animation?

I would appreciate some help!

The code

extends KinematicBody2D

var is_moving_left = true
var gravity = 10
var velocity = Vector2(0, 0)

var speed = 32

func _ready():
$AnimationPlayer.play(“E1 RUN”)

func _process(_delta):
if $AnimationPlayer.current_animation == “E1 ATTACK”:
return

move_character()
detect_turn_around()

func move_character():
velocity.x = -speed if is_moving_left else speed
velocity.y += gravity

velocity = move_and_slide(velocity, Vector2.UP)

func detect_turn_around():
if not $RayCast2D.is_colliding() and is_on_floor():
is_moving_left = !is_moving_left
scale.x = -scale.x

func hit():
$AttackDetector.monitoring = true

func end_of_hit():
$AttackDetector.monitoring = false

func start_walk():
$AnimationPlayer.play(“E1 RUN”)

func _on_PlayerDetector_body_entered(body):
$AnimationPlayer.play(“E1 ATTACK”)

func _on_AttackDetector_body_entered(body: Node) → void:
get_tree().reload_current_scene()

:bust_in_silhouette: Reply From: exuin

Not going to watch the video, but don’t you want to check IF the raycast is colliding instead of if it’s not?

OMG. YOU WERE TALKING ABOUT THE CODE. IT WORKED. YOU’RE A GOD.
THANK YOU SO MUCH!!!

Erto | 2023-03-03 14:22