Hello friends! I have a problem, I want my NPC to move towards some coordinates, but it doesn’t, so I make it draw a line from its current position to the target position and the line is drawn correctly but the movement is wrong. The objective is that the NPC must generate a path, then it must travel that path and start the process again, can you help me with that?
You are setting your new point as velocity. What you want to do instead is: velocity = (new_pos - global_position).normalized() * delta * speed
To get the direction towards the new point. Also if your npc is a CharacterBody2D you should not use delta in the calculation, since CharacterBody2D adjusts the velocity based on delta on its own.
Your code for detecting if the new point is reached should also be adapted to check for the distance between your two points being below a certain threshold.
Edit: Added normalization to the direction as well, so that it has a uniform length of 1. Otherwise the movement speed will not be consistent.