CollisionShape2D in another node

tcp2000tcp2000 Posts: 2Member

Really love Godot!
I understand disabling a CollisionShape2D however the one I want to disable is in the node above.
The script I'm in is DiceButton and I want to go up a node to SpiderColl and disable that.
Please help!

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 3,525Admin

    Maybe something like this: get_parent().get_node("SpiderColl").disabled = true? It might not be the best way to handle it, but it might work in a pinch.

    You could also try something like this, for a little more flexibility at the cost of some additional complexity:

    Extends Button
    export (NodePath) var path_to_collision_shape = null
    var _parent_collision_shape
    
    func _ready():
        if (path_to_collision_shape != null):
            _parent_collision_shape = get_node(path_to_collision_shape)
            # example: disable the collision shape
            _parent_collision_shape.disabled = true;
        else:
            print ("ERROR: you need to assign the NodePath to the collision shape in the Godot editor!")
    

    Hopefully this helps!
    (Side note: welcome to the forums)

  • tcp2000tcp2000 Posts: 2Member

    Sorted it by using
    $potionCollision.call_deferred("set_disabled", true) in the Area2D script

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file