Files
millimeters-of-aluminum/scenes/characters/player_controller.gd
2025-10-13 13:12:56 +02:00

38 lines
1.3 KiB
GDScript

extends Node
class_name PlayerController
# TODO: Change this to custom pawn type
var possessed_pawn: Node # The character this controller is currently driving
func _ready():
# --- FIX: Manually enable input processing for this node ---
set_process_input(true)
func _physics_process (delta):
if not is_multiplayer_authority():
return
# 1. Gather all input states for this frame.
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
var is_interact_just_pressed = Input.is_action_just_pressed("interact")
var is_interact_held = Input.is_action_pressed("interact")
#print(is_interact_just_pressed)
#print(input_dir)
# 2. Send the collected input state to the server via RPC.
server_process_input.rpc_id(1, input_dir, is_interact_just_pressed, is_interact_held)
@rpc("any_peer", "call_local")
func server_process_input(input_dir: Vector2, is_interact_just_pressed: bool, is_interact_held: bool):
if is_instance_valid(possessed_pawn):
possessed_pawn.set_movement_input(input_dir)
# Pass both interact states to the pawn
possessed_pawn.set_interaction_input(is_interact_just_pressed, is_interact_held)
func possess(pawn_to_control: Node):
possessed_pawn = pawn_to_control
reparent(pawn_to_control, false)
self.owner = pawn_to_control
print("PlayerController possessed: ", possessed_pawn.name)