Collision Not Working For Interactable Object

Godot Version

4.5

Question

(I’m sure Im just missing something but here goes :D)

My interactable object works, it disappears, it prints what it needs to in the debug window, but there are three problems that ive tried to fix and couldn’t:

  1. You can interact with the object from wherever you are in the level. I need it to just fit the object.
  2. The label pops up in the corner of the game window and stays. It doesn’t show up on top of the object when you get close, like its supposed to. Although, this could just be because I’m doing this in 3D - I deleted the node, but if anyone knows how to make those work in 3D that would be great :slight_smile:
  3. The interactable object does not become uninteractablle, when i press E more than once it keeps printing ‘memory’.

Interact Script:

extends Area3D

@export var interact_name: String = ""
@export var is_interactable: bool = true

var interact : Callable = func():
	pass

interactable_instance script:

extends Node3D

var current_interactions := []
var can_interact := true


func _input(event: InputEvent) -> void:
		if event.is_action_pressed("interact") and can_interact:
			if current_interactions:
				can_interact = false
			
				await current_interactions[0].interact.call()
			
				can_interact = true



func _process(_delta: float) -> void:
		if current_interactions and can_interact:
			current_interactions.sort_custom(_sort_by_nearest)
		
	
func _sort_by_nearest(area1, area2):
	var area1_dist = global_position.distance_to(area1.global_position)
	var area2_dist = global_position.distance_to(area2.global_position)
	return area1_dist < area2_dist
	
func _on_area_3d_area_entered(area: Area3D) -> void:
	current_interactions.push_back(area)


func _on_area_3d_area_exited(area: Area3D) -> void:
	current_interactions.erase(area)

And heres my VHS tape/object script:

extends AnimatableBody3D

@onready var interactable: Area3D = $Interact

func _ready() -> void:
	interactable.interact = _on_interact
	
	
func _on_interact():
	hide()
	interactable.is_interactable = false
	print("Memory")

You don’t seem to check the value of can_interact when running the interaction logic, so the interaction function will always run. You should only run the function if the player should be able to interact with the object.

For the label, were you using a 2D or a 3D one?

Ooooooh, how do i add that paramater?

And i was using a green one, although i think it was 2d

You can pass parameters to the call function.

If you want the label to appear in a 3d environment, you need to use a 3d label.

1 Like

okay :slight_smile:

I think i have the right code (i did take it from you so thank you very much!!), but how do i set the max distance?

extends Area2D

@export var interact_name: String = ""
@export var is_interactable: bool = true
@onready var Player = $"Player (LowPoly For Game)"

var interact : Callable = func():
	if Player.global_position.distance_to(global_position) > max_distance:
		is_interactable = false

The max distance is whatever you want it to be, you set it yourself?

ooooh, wait, i just put the number i want right after the ‘:’?

i thought i would have to put another thing, like coordinates or something :,D

thats why i was confused sorry

when i put it in now, it doesnt wrk, so i think i misunderstood

extends Area2D

@export var interact_name: String = ""
@export var is_interactable: bool = true
@onready var Player = $"Player (LowPoly For Game)"

var max_distance = 1

var interact : Callable = func():
	if Player.global_position.distance_to(global_position) > max_distance:
		is_interactable = false

1 Like

The distance uses pixels as units. If you have 1 as the max distance, it’s 1 pixel.