Files
godot-demo-projects/viewport/split_screen_input/player.gd
Markus Sauermann 10eb2807b8 Add Split Screen Demo showing input handling (#1023)
* Add Split Screen Demo showing input handling

* Style fixes, layout improvements, update to Godot 4.5

---------

Co-authored-by: Aaron Franke <arnfranke@yahoo.com>
2025-10-01 22:56:48 -07:00

29 lines
1.0 KiB
GDScript

class_name Player
extends CharacterBody2D
## Player implementation.
const factor: float = 200.0 # Factor to multiply the movement.
var _movement: Vector2 = Vector2(0, 0) # Current movement rate of node.
# Update movement variable based on input that reaches this SubViewport.
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("ux_up") or event.is_action_released("ux_down"):
_movement.y -= 1
get_viewport().set_input_as_handled()
elif event.is_action_pressed("ux_down") or event.is_action_released("ux_up"):
_movement.y += 1
get_viewport().set_input_as_handled()
elif event.is_action_pressed("ux_left") or event.is_action_released("ux_right"):
_movement.x -= 1
get_viewport().set_input_as_handled()
elif event.is_action_pressed("ux_right") or event.is_action_released("ux_left"):
_movement.x += 1
get_viewport().set_input_as_handled()
# Move the node based on the content of the movement variable.
func _physics_process(delta: float) -> void:
move_and_collide(_movement * factor * delta)