Download Player/scripts/input.gd from NeatoGames/saddle-up: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/datasets/NeatoGames/saddle-up/resolve/main/Player/scripts/input.gd
- Command line
-
hf download hf://datasets/NeatoGames/saddle-up/Player/scripts/input.gd
-
curl -L -o input.gd https://huggingface.co/datasets/NeatoGames/saddle-up/resolve/main/Player/scripts/input.gd
1.97 kB
| extends Node | |
| @onready var player: Node3D = $".." | |
| @onready var player_camera: Node3D = $"../PlayerCamera" | |
| @onready var character: Node3D = $"../Character" | |
| func handle_input() -> Dictionary: | |
| var actions : Array[String] = [] | |
| var combat_actions : Array[String] = [] | |
| var input_direction : Vector2 | |
| actions.append('Idle') | |
| input_direction = Input.get_vector('left', 'right', 'up', 'down') | |
| # Transform input direction to be relative to camera's horizontal rotation only | |
| # Get the camera's forward direction (the direction it's looking, ignoring vertical tilt) | |
| # Use the PlayerCamera's Y rotation, not the Player's | |
| var camera_y_rotation = player_camera.rotation.y | |
| var camera_forward = Vector3(-sin(camera_y_rotation), 0, -cos(camera_y_rotation)).normalized() | |
| var camera_right = camera_forward.cross(Vector3.UP).normalized() | |
| # Build direction from input: forward/back and left/right | |
| # input_direction.y: negative = forward (W), positive = back (S) | |
| # input_direction.x: negative = left (A), positive = right (D) | |
| var direction = (-input_direction.y * camera_forward + input_direction.x * camera_right).normalized() | |
| # Movement | |
| if input_direction != Vector2.ZERO: | |
| actions.append('Walk') | |
| if Input.is_action_pressed('run'): | |
| actions.append('Run') | |
| elif Input.is_action_pressed('crouch'): | |
| actions.append('Crouch') | |
| # Roll | |
| if Input.is_action_pressed('roll'): | |
| actions.append('Roll') | |
| # Jump | |
| if Input.is_action_pressed('jump'): | |
| if actions.has('Crouch'): | |
| actions.remove_at(actions.find('Crouch')) | |
| elif actions.has('Sprint'): | |
| actions.append('JumpSprint') | |
| else: | |
| actions.append('JumpWalk') | |
| return { | |
| 'input_direction': input_direction, | |
| 'direction': direction, | |
| 'actions': actions, | |
| 'combat_actions': combat_actions, | |
| 'basis': player_camera.basis, | |
| 'on_move': func(): | |
| print(character.find_child('CharacterBody').transform.basis) | |
| #player.transform.basis = character.find_child('CharacterBody').transform.basis | |
| } | |