0 votes

When raycasting using: var result = space_state.intersect_ray(get_global_pos(), global.PLAYER_POS, [ self ] ); where [ self ] is an array of objects to exclude from collision, how would I go about excluding player-spawned collision objects (such as bullets?).

I add them all to single node, "World Objects", and I was wondering if there was a way to specify to exclude all collision objects who are children of that node?


in Engine by (45 points)

1 Answer

+1 vote
Best answer

Your title doesn't really match what you're asking. It seems like you understand the idea of an exclusion array already.

It seems to me you want to know more about how to track references.

Two immediate options are:

A) Use an array that stays in scope, and at the point of code where all projectiles are created, append their reference to that array, and at their point of despawn you would then remove them.

B) If you just want to build the array every frame from children in a certain node you would do something like this:

var node = get_node("path goes here")

var exclusion_list = []

for child in node.get_children():

var result = space_state.intersect_ray(get_global_pos(), global.PLAYER_POS, exclusion_list)
by (5,274 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.