• 2D
  • Help to understand colisions on raycast

Hi Folks

Recently I dig into a "laser beam" kinda effect and found a short tutorial:

and works fine... The "beam" colides with the CollisionShape2D in the StaticBody2D

Well, the thing is, when I put the LaserBeam scene into the game, it doesn't colide with other objects (the enemy in this image has an area2D with a colisionshape):

how can I handle this colisions? Thanks

If I had to guess, the problem is that the raycast cannot detect the Area2D node. If you set collide_with_areas (documentation) to true on the Raycast2D, then that should hopefully fix the problem.

Amazing... thank you! <3

And can I choose with areas colide is active? I use to group areas with, hummm... for instance: add_to_group("ship") add_to_group("enemy_simple") add_to_group("enemy_bullet")

and with this collision, emiting signals or trigger some function? I know hot to do with "bullets" made of Area2D(+CollisionPolygon2D, etc), but I still really lost working with raycast

If you are using a Raycast2D node, you can put the bullets on a different collision layer/mask than the Raycast2D (or vise versa) and the Raycast2D node should ignore them. I'm not sure if there is a built-in way to have a Raycast2D node ignore a group. You can add each node in the group as an exception and then call add_exception (documentation) but it will not react to new nodes added to the group unless you call add_exception again.

Excellent idea! Thank you very much

	var enemyBullets = get_tree().get_nodes_in_group("enemyBullets")
	for i in enemyBullets:
		add_exception(i)

works like a charm! thanks again