How to check the direction of my AI

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

I have a AI and I have Animations for that AI.I added all the AI animations but I have to flip the animations if its going right or left.In my player I could do that by saying if my velocity is negative,flip the animations or vice versa.But the code used in my AI is different.
AI code:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

extends Node2D

var places = 0
var speed = 400
var path = PoolVector2Array() setget set_path
var stop = false
var OnetimeTimer = true
var RandomPlaces = [0,1,2]
var dead = false

func _process(delta):
if dead == false:
RandomPlaces = [randi() % 3]
var move_distance = speed * delta
move_along_path(move_distance)
if stop:
$AnimatedSprite.play(“idle”)
if OnetimeTimer:
$NextTask.start()
OnetimeTimer = false
else:
$AnimatedSprite.play(“run”)

else:
$AnimatedSprite.play(“dead”)

func move_along_path(distance:float):
var start_point = position
for i in range(path.size()):
var distance_to_next = start_point.distance_to(path[0])
if distance < distance_to_next and distance>= 0.0:
position = start_point.linear_interpolate(path[0],distance / distance_to_next)
break
elif distance < 0.0 :
position = path[0]
break
distance -= distance_to_next
start_point = path[0]
path.remove(0)

func set_path(value : PoolVector2Array):
path = value
if value.size() == 0:
return

func _on_NextTask_timeout():
$NextTask.stop()
if RandomPlaces == [0] and places != 1:
get_parent().next_place2 = get_parent().get_node(“positions/electric”)
elif RandomPlaces == [0] and places == 1:
$NextTask.start()
if RandomPlaces == [1] and places != 2:
get_parent().next_place2 = get_parent().get_node(“positions/shield”)
elif RandomPlaces == [1] and places == 2:
$NextTask.start()
if RandomPlaces == [2] and places != 3:
get_parent().next_place2 = get_parent().get_node(“positions/admin”)
elif RandomPlaces == [2] and places == 3:
$NextTask.start()

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Sorry If my code is hard to read (i am not able to put as the code sample)
I use Navigation2d (tile map one) in my AI to go to places in the map.
Also how to add collisions to these bodies because if I have a static body it doesn’t collide with.Even if my AI is a Body it doesn’t collide with static bodies.Please help

to format the code as a code sample, just select it and click the {} button.

Millard | 2020-11-30 17:22

Oh ok ,Thanks for that

RRocky123 | 2020-11-30 23:56