how can i exclude all mobs when using intersect_ray()?

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

so i want to exlude all mobs in map

if i put space_state.intersect_ray(position, player.position, [self,get_parent().get_node("mobs")], collision_mask)
it only exclude the first mobs spawn with that name

if i put space_state.intersect_ray(position, player.position, [self,get_tree().get_nodes_in_group("mobs")], collision_mask)
it wont exclude any mobs

what should i do

this my mob code

func sight_update():
	if player_in_range == true:
		var space_state = get_world_2d().direct_space_state
		var sight_check = space_state.intersect_ray(position, player.position, [self,get_parent().get_node("mobs")], collision_mask)
		if sight_check:
			if == "player":
				player_in_sight = true
				$icon.modulate = Color(255,255,255,1)
				print(," player in sight = ", player_in_sight, " = ",sight_check.position)
				player_in_sight = false
				$icon.modulate = ColorN("crimson",1)
				print(," player not in sight = ", player_in_sight, " = ",sight_check.position)

Are your mobs collision objects? Have you tried giving an array of RID instead?

You could also try using a RayCast2D node that allows usage of collision layers.

Maveyyl | 2021-05-11 21:41

yes collision object. what is RID ? RID — Godot Engine (stable) documentation in English

potatobanana | 2021-05-11 23:50

in the doc of function intersect_ray it is said you can give it an array of collision object or an array of rid. Rids are identifiers used by the physics engine to identify physics objects such as collision objects and shapes. You can get them by calling “get_rid()” on any collision object.

Maveyyl | 2021-05-11 23:52