Within scenes/player/player.gd
and scenes/player/cursor.gd
there is a concept of interactable objects. These are objects on the map that the player can interact with using their cursor.
When the player clicks the cursor Player
calls interactables_under_cursor()
on Cursor
and begins to process all of the objects returned by it.
In order for an object to qualify as an interactable under the cursor the following conditions must be true:
interact()
interact_range:int
map_position:Vector2
Player.map_position
and Interactable.map_position
must be less than or equal to Interactable.interact_range
Additionally one of the following must be true:
CollisionShape2D
that is overlapping with the Cursormap_position
equal to the map_position
of the Cursor
Please note the use of global_position
not position
in the setter and getter for map_position
.
extends Node export (int) var interact_range: int = 1 var map_position: Vector2 setget _set_map_position, _get_map_position func interact(): pass func _set_map_position(new_position: Vector2): global_position = Services.MapManager.map_to_world(new_position) func _get_map_position() -> Vector2: return Services.MapManager.world_to_map(global_position)