How can I make an object send raycast3D towards objects in a specific group

Godot Version

4.3

Question

My goal is to make a granade that when explodes it sends out a straight line of lightning toward anything that is metal. So how can I send out a raycast3D from the granade object toward any object that is in the target metal group?

I want the lightning range to be really big so its probably not a good idea to use an area3D cause it could lag probably?

An area 3d would would not cause any lag and you if you still wanted to use the raycast 3d method you make the raycasts, make a script where on contact make sure its an enemy, if it is do damage , if not do nothing. (But an area 3d would probably work fine but let me know if im wrong)

You could use a different collision layer for your metal objects. It’s a bit more manual work to also set things into the correct layer. You could try and script this, by checking the group and automatically setting the collision layer (I’m not entirely sure where/how the best way to do this would be, but it’s certainly possible).

Edit: This would be if using an Area3D.

1 Like

I’d do something like this:

  • First, Put any metal objects into a Metal group.
  • Create a damage range from grenade to surround objects, using a sphere area3D.
  • Check any objects within damage area, using area3D on_area/body_entered
  • Check if any of those objects are in Metal group, using is_in_group
  • Using Metal Object position as end point of raycast
2 Likes