Ok my bad i forgot to update Move() every frame :3
also i wil post the code again so if somebody look this up don't just copy it the don't get wrong outputs , there are some errors in the code that makes the npc disappear because its position becomes NAN :#
private void Move(){
Vector2 distanceBetween = playerPosition.GetCurrentPosition() - this.Position;
if(Math.Abs(distanceBetween.x) > maxDistance.x){ /* check if the distance between player
and npc is not greater than max ditance */
//GD.Print(distanceBetween);
if(distanceBetween.x < 0){
motion.x = Mathf.Lerp(motion.x, -maxSpeed, 0.1f); //speed up to maxspeed
}
else{
motion.x = Mathf.Lerp(motion.x, maxSpeed, 0.1f); //speed up to maxspeed
}
}
else{
motion.x = Mathf.Lerp(motion.x, 0, 0.1f); // to stop npc
}
if (Math.Abs(distanceBetween.y) > maxDistance.y)
{
if (distanceBetween.y < 0)
motion.y = Mathf.Lerp(motion.y, -maxSpeed, 0.2f);
else
motion.y = Mathf.Lerp(motion.y, maxSpeed, 0.2f);
}
else
motion.y = Mathf.Lerp(motion.y, 0, 0.2f);
}