Are Raycast Shapes available in Godot?

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

Hello,

I’m creating a game where the player can cast spells towards objects that are in front of him. To know which object it will hit, I cast a ray and get the collider. This works.

However, often an object is just a little to the side, and not picked up. The ray is simply too thin. It’s frustrating, because you’re sure the player is aiming in the right direction, but it’s just too hard to reach the object you want.

So, what I need, is to cast a (probably square) shape to cover everything the player should be able to see/hit. The whole area in front of the player.

Is this possible in Godot? Or do I have to, say, use 9 parallel raycasts to cover a square area in front of the player? Or do I have to resort to using an Area with a cube shape?

I know, for example, that Unity has a RayCastSphere function, where you can cast rays to get everything in front of the player between certain angles. Something like that would be great.

Thanks in advance!

:bust_in_silhouette: Reply From: p7f

Hi, if you are using KinematicBody2D, you can use the function test_move() to see if a collision would occur. Then you would need to do some raycasts to get the position of the collision. I did this for a teleport, and worked, but i had to use several raycast to cover the area. However, if test_move gave you a collision happened, you know one of the raycast should return a collision also, and if it does no, you should keep trying with other raycasts.

In godot 3.0.6 you cant raycast a shape, but this feature is going tonbe available in godot 3.1 acoording to this but i think they are for a different use…

I am indeed using a KinematicBody (in 3D). And wow, how have I never encountered the test_move() function before? It’s really nice. I don’t know if it’s any faster, though, than simply adding multiple raycasts and looping through them (checking each of them for collision, and then taking the closest one). Guess I’ll just try both techniques and see which one’s faster/more accurate.

I also read that article; those raycast shapes are indeed for a different use. Too bad Godot doesn’t support the raycast shapes like Unity. But at least there’s other ways to do it.

Pandaqi | 2018-12-23 22:18

:bust_in_silhouette: Reply From: d2clon

I am in a similar situation and I am solving it using Area2D.get_overlapping_bodies()