0 votes

I need to build a bit flag to pass to PhysicsDirectSpaceState.intersect_ray(). To do this, I need the index of the 3d physics layer I've named 'Player' in Project Settings/Layer Names. Rather than hardcoding this flag in my script, is there a way for me to query the API to find out what flag index I gave to the layer "Player"?

in Engine by (154 points)

Are you referring to the collision layer?

Yes. The value you enter in the Project Settings/Layer Names/3d Physics spreadsheet.

1 Answer

0 votes

I think you need something like this:

func layer_index_from_name(target_name):
    for i in range(0, 19, 1):
        var layer_name = ProjectSettings.get_setting("layer_names/3d_physics/layer_" + str(i+1))
        if layer_name == target_name:
            return int(pow(2,i))
    return null

func _ready():
    var look_for = "test"
    var res = layer_index_from_name(look_for)
    if res: 
        print("Not found")
by (611 points)
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.