User Tools

Site Tools


docs:interactables

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:

  • It must have a method: interact()
  • It must have a property: interact_range:int
  • It must have a property: map_position:Vector2
  • The distance between 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:

  • It must have a CollisionShape2D that is overlapping with the Cursor
  • It must have a map_position equal to the map_position of the Cursor

Minimal Interactable

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)
docs/interactables.txt · Last modified: 2021/02/11 01:47 by 94.198.42.250