0 votes

So I'm making an NPC with a kinematicbody2d follow a path by having it linear interpolate to each point in the path. The issue that I'm having is that I want to detect when it's moving so that I can implement a walking animation, but since it's moving through linear interpolations I can't have it detect through velocity, and I'm having trouble figuring out other ways to achieve this.

This is what makes it move:
self.global_position = StartPoint.linear_interpolate(NewPath[0], .15)

Any help?

in Engine by (33 points)

1 Answer

+1 vote

A movement is a change of position over time, no matter if it was interpolated or not. To detect movement (such change) you should compare current position with position stored in previous process step.

var object : Node2D
var old_pos : Vector2 = object.position

func _process(delta: float) -> void:
  if old_pos != object.position:
  old_pos = object.position

Please note, with such comparison you should take in account float precision errors.

by (1,636 points)
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 Frequently asked questions and 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.