Detecting linear_interpolation movement

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

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?

:bust_in_silhouette: Reply From: sash-rc

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:
    print("moving")
  old_pos = object.position

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