2024-04-17 03:26:13 +00:00
|
|
|
extends CharacterBody2D
|
2024-04-15 23:44:06 +00:00
|
|
|
class_name Cursor
|
|
|
|
|
2024-04-17 03:26:13 +00:00
|
|
|
## A [CharacterBody2D] syncing its position with the mouse on each physics timestep.
|
2024-04-15 23:44:06 +00:00
|
|
|
|
|
|
|
|
2024-04-19 02:30:35 +00:00
|
|
|
@onready var game := MainGame.get_via_group(self)
|
2024-04-15 23:44:06 +00:00
|
|
|
|
|
|
|
|
2024-04-20 00:17:40 +00:00
|
|
|
static func get_via_group(node: Node) -> MainGame:
|
|
|
|
var result = node.get_tree().get_nodes_in_group("cursor")
|
|
|
|
if result.is_empty():
|
|
|
|
return null
|
|
|
|
return result[0]
|
|
|
|
|
|
|
|
|
2024-04-15 23:44:06 +00:00
|
|
|
func _physics_process(_delta: float) -> void:
|
2024-04-17 03:26:13 +00:00
|
|
|
move_and_collide(game.camera.get_global_mouse_position() - global_position)
|