0 votes

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 sight_check.collider.name == "player":
                player_in_sight = true
                $icon.modulate = Color(255,255,255,1)
                print(self.name," player in sight = ", player_in_sight, " = ",sight_check.position)
            else:
                player_in_sight = false
                $icon.modulate = ColorN("crimson",1)
                print(self.name," player not in sight = ", player_in_sight, " = ",sight_check.position)
in Engine by (382 points)
edited by

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.

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.