Help with the door label

Godot Version

4.7.stable

I’m new to Godot and I’m having a problem with the door label.

This is the scene at the door

The CollisionShape3D of both Area3D and StaticBody3D have the same dimensions.

This is the CollisionShape3D script for the door

extends StaticBody3D

var Open1 := false
var Interact := true
@export var Animation_Door: AnimationPlayer

func interact_door():
	if Interact == true:
		Interact = false
		Open1 = !Open1
		if Open1 == false:
			Animation_Door.play("close_door")
		if Open1 == true:
			Animation_Door.play("open_door")
		await get_tree().create_timer(1.0, false).timeout
		Interact = true

This is how I have constructed the character.

This CharacterBody3D script is designed to make the label appear on the door if Raycast3D detects an Area3D.

@onready var label: Label = $Control/Label
@onready var raycast: RayCast3D = $Node3D/RayCast3D


#----------------------


func _process(_delta: float) -> void:
	if raycast.is_colliding():
		var colision = raycast.get_collider()
		if colision is Area3D:
			label.text = "[E]"
	else:
		label.text = ""

This is the script RayCast3D calls the door function

extends RayCast3D

func _process(_delta):
	if is_colliding():
		var Activate = get_collider()
		if Activate.has_method("interact_door") and Input.is_action_just_pressed("accion"):
			Activate.interact_door()

The problem is that only 1 out of 2 things works.

  1. The label appears but I can’t open the door.
  2. The door opens but the label doesn’t appear.

How can I fix this? Where is it done incorrectly?

Thank you very much.

Your door script is only on the StaticBody3D, if they raycast stops on the Area3D then it’s impossible to interact with the door. You probably do not need the Area3D, instead use the same check for your player script and your raycast script.

I deleted Area3D
I changed the characterbody3d script

func _process(_delta: float) -> void:
	if raycast.is_colliding():
		var colision = raycast.get_collider()
		if colision is CollisionShape3D:
			label.text = "[E]"
	else:
		label.text = ""

and I have no idea what to put in the raycast script.

I’m missing something.

It would be if collision is StaticBody3D not CollisionShape3D, but that still doesn’t match your raycast’s condition of if collision.has_method("interact_door")

I think I did that before.

The problem is that there will be more Staticbody3d objects like walls, and the tag will appear everywhere.

No, if you use the same condition as your raycast, has_method("interact_door") then it will only appear with static bodies that have a script with such a function, not all walls.

It worked! Thank you so much!