How do you make an enemy detect the player using RayCast2D?

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

Noob question (college freshman programmer)

May I ask how do you make an enemy detect the player using RayCast2D?

The NPC I made is just walking endlessly unless it hits a wall/object/KinematicBody2D) or it’s on an edge, then it will go the other way. And I don’t want it to go the other way if it hits a KinematicBody2D…

I am not well-versed in Godot Scripts, so it would help me a lot in this project (a group project required to pass this course) if someone can share their knowledge with me.

Thanks!

I’m using C# with this Godot