NPC and its random movement

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

Hello there!

Since I know how to move my player in my 2d top-down space game, I would like to create some NPC too. But I don’t actually know how to do it.

  1. NPC movement
    I think that using a kinematicBody2D should be fine, but how to make it move in a random direction with its speed and after some time, calculate new direction and also turn the NPC by its turn speed?

  2. NPC field of view
    Also, I’ve read the docs about the dot product. But I actually didn’t get the logic. I mean, when a player enters the NPC radar range (Area2D should be good for that), how to also turn the NPC to face the player?

I searched on google for AI and NPC tutorials for Godot but I haven’t found the answer.

Please, I am still new to programming so further explanation for everything would be welcomed.

Thank you in advance! :slight_smile: