Nearby clickables in point-and-click game

Godot Version

4.7

Question

I’m making a point-and-click visual novel game, sort of in the style of Ace Attorney, wherein each scene is a room with clickable objects. My dialog system currently works so that upon clicking an object (which is set up as a Sprite2D → CollisionArea2D → CollisionShape/CollisionPolygon), the empty dialog box (which is a CanvasLayer node) receives a signal from the Area2D, loads a JSON file, and displays the correct text.

The issue I am having is overlap in the Area2D, which is causing a click on both objects to be parsed even when the mouse is only clicking on one. I’m not sure how to fix this; ideally, the click would only be parsed when precisely on the clickable object, as some objects in the game are rather close together.

I tried custom setting the viewport object picking physics, and considered instantiating another signal from each Area2D to check the mouse’s hover location right before clicking, but couldn’t get it to work.

As this is my first game, I’m still getting things like signal implementation mixed up fairly often, so I would greatly appreciate any help or resources that might be good, as I haven’t found a ton in the way of this specific problem, and have combed through the official Godot documentation at length…

For a sample scene, I have this–two sprites and a textbox:

And the code for the Area2D on each sprite is as such:

extends Area2D

signal call_dialog 

func _input(event: InputEvent):
	if event.is_action_pressed("click"):
		call_dialog.emit()

And, finally, this is dialog box script as:

# rightmost sprite
func _on_jooyeonclickarea_call_dialog(): 
	print("first signal passed")
	get_json(jsonsrc)
	char_text.show()
	speaker_name.show()
	load_block(current_block)


#leftmost sprite
func _on_junhanclickarea_call_dialog():
	print("second signal passed")
	get_json("res://json/jh-demo.json")
	char_text.show()
	speaker_name.show()
	load_block(current_block)

Thank you for any help possible… This seems to be the last major obstacle in implementing the basic player interaction for this game, so I’ll keep trying things as well, and I’m excited to hopefully get this sorted quickly..!

Shouldn’t the areas of different clickable objects be arranged in a way that they don’t overlap?

they are, as far as i know. maybe i’m missing something, but the area2d and collision polygons are separate, it looks like this.

You should use Area2D’s input_event signal to detect clicks on them.

i’ve been trying this, but i’m a bit confused about the parameters, particularly shape_idx…

You don’t need shape_idx. Connect each area’s signal to its own handling function. If you want to connect all of them to the same function, you’ll need to bind an additional argument when making connections, that identifies the area that sent the signal.