I managed to solve my previous issue, but a new issue popped up.
I can't change the blue entity's animation whenever it is pathfinding. It is stuck facing the same direction. I tried getting its velocity variable, but it does nothing.
extends KinematicBody2D
var speed = 150
var path = []
var Move
onready var goal = get_parent().get_node("RedGhola").get_global_position()
func _ready():
set_physics_process(true)
update_path()
func update_path():
path = get_parent().get_node("Nav").get_simple_path(get_position(),goal,false)
func _physics_process(delta):
var d = get_position().distance_to(path[0])
if path.size() > 1:
if d > 2:
set_global_position(get_global_position().linear_interpolate(path[0], (speed*delta)/d))
else:
path.remove(0)
func rerun():
goal = get_parent().get_node("RedGhola").get_global_position()
path = get_parent().get_node("Nav").get_simple_path(get_position(),goal,false)
Any help on this? I need to access its velocity so that it will change animations depending where its going. The rerun function allows the blue entity to keep on targetting new instances of its food.