I want to make sprite that can cover my character when he is crouching (like a stealth mode)

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

I just started learning Godot and i don’t have enough knowledge to make a big piece of my ideas. I have a Sprite of a tree in a pot, and i want to make this Sprite possible to cover my character, like he is behind Sprite, but ONLY when ‘ui_down’ action is pressed. Thanks for your future anwers :stuck_out_tongue_winking_eye:

:bust_in_silhouette: Reply From: Hunter99

Let’s assume you have following tree structure:

  • Node2D
    |---- Sprite1 (Player)
    |---- Sprite2 (Tree)

You could create a script in the Node2D node with:

func _process(delta):
    if Input.is_action_pressed("ui_down"):
        if not $Sprite2.visible:
            $Sprite2.visible = true
        $Sprite2.position = $Sprite1.position
        if $Sprite2.visible:
            $Sprite2.visible = false

Since the tree node is after the player node in the node tree, it will be drawn over the player.