raycast2d doesn't work

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

I’m trying to make the enemy to play animation in specific directions, but the raycast not working

extends AnimatedSprite

onready var bigchunk = get_node("/root/world/YSort/BigChunk").global_position
onready var player = get_parent().get_node("/root/world/YSort/Player").global_position
onready var bigchunkright = preload("res://bigchunkrights.tscn").instance()
onready var bigchunkleft = preload("res://bigchunklefts.tscn").instance()

func _ready():
 connect("animation_finished", self, "on_animation_finished")

func _process(delta):
 for right in bigchunkright.get_children():
	if right.is_colliding():
		if bigchunk.x >= player.x:
		if bigchunk.x <= player.x:
 for left in bigchunkleft.get_children():
	if left.is_colliding():
		if bigchunk.x >= player.x:
		if bigchunk.x <= player.x:

func on_animation_finished():

pls help

:bust_in_silhouette: Reply From: timothybrentwood

You are playing the same animation, “deadright”, regardless of what if conditional is true. This is a copy/paste error.

My god, I forgot to check if someone gonna answer this, by the way, I have already fixed my problem with this:

func _on_start_no_health():
is_dead = true
_player = null
$shadow.visible = false
if player.position.y >= position.y:
	anim_player.play("Dead Down")
if player.position.y <= position.y:
	anim_player.play("Dead Up")
for L in $bigchunkbothsides.get_children():
	if L.is_colliding():
		if player.position.x <= position.x:
			anim_player.play("Dead Left")
		if player.position.x >= position.x:
			anim_player.play("Dead Right")

But still thanks for your help, seeing someone answer my silly problem really make my day :v

cookieoil | 2021-09-05 08:38