Spherical ray cast?

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

I remember in Unity there is a spherical ray cast which I can use for detecting enemy. Is there something similar or should I just use something like area 2D for detecting ?

:bust_in_silhouette: Reply From: kidscancode

Use Area2D (2D) or Area (3D) for this.

Thank you, I suspected as much

lowpolygon | 2019-06-04 03:03

Would this be cut off by obstacles like raycasts are though?

Example: I want enemies to be able to detect the area that is in the player’s line of sight, so they can do simple things like take the shortest path towards LoS on player, for simple but efficient ranged aggression.

Was thinking a circlecast 2D on player (On target in code, player typically being the target) would do the job of distinguishing said area for the AI to recognize it… I feel like I’m simultaneously overcomplicating and oversimplifying it, but can’t find other people’s method to create these behaviors.

KelvinM6 | 2020-02-17 18:23

No, but this will tell you if the player is in visibility range. Then, for LOS, you need to cast a ray to see if there are obstacles in the way. Or you can use a shapecast. See PhysicsDirectSpaceState.

There are many approaches to this - it depends on exactly what behavior you’re going for.

kidscancode | 2020-02-17 18:29


I’m very much interested on how you could achieve what the Physics.Raycast function of unity (Unity - Scripting API: Physics.SphereCast) does in godot (with the point/normal information). Thanks in advanced.

panicq | 2020-03-09 21:54