0 votes

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.

in Engine by (26 points)
edited by

I don't see any code for animation here. Do you actually mean you want the blue entity to face the direction it's going? In that case, try

look_at(goal)

http://docs.godotengine.org/en/3.0/classes/class_node2d.html#class-node2d-look-at

I was trying to implement some code, and I've managed to have it face in the direction of its food source. It has separate animations for forward and backward. The game itself happens to be isometric, so it can't rotate while pathfinding. It either has to switch animations, flip itself horizontally or both. What I want to do is that the blue entity faces each point on its pathfinding algorithm as it moves.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.