163 lines
7.6 KiB
GDScript
163 lines
7.6 KiB
GDScript
extends CharacterBody3D
|
|
|
|
@export_group("Movement")
|
|
@export var movement_speed : float = 5.0
|
|
@export var movement_speed_change_delta : float = 0.5
|
|
|
|
@export_group("Inputs")
|
|
@export_subgroup("Keyboard")
|
|
@export var keyboard_move_forward : InputEventKey
|
|
@export var keyboard_move_backward : InputEventKey
|
|
@export var keyboard_move_left : InputEventKey
|
|
@export var keyboard_move_right : InputEventKey
|
|
@export var keyboard_move_up : InputEventKey
|
|
@export var keyboard_move_down : InputEventKey
|
|
|
|
@export var keyboard_tilt_up : InputEventKey
|
|
@export var keyboard_tilt_down : InputEventKey
|
|
@export var keyboard_pan_left : InputEventKey
|
|
@export var keyboard_pan_right : InputEventKey
|
|
|
|
@export var keyboard_movement_speed_up : InputEventKey
|
|
@export var keyboard_movement_speed_down : InputEventKey
|
|
|
|
@export var keyboard_place_marker : InputEventKey
|
|
@export var keyboard_exit_placement : InputEventKey
|
|
|
|
@export_subgroup("Mouse")
|
|
@export var mouse_tilt_up : InputEventMouseMotion
|
|
@export var mouse_tilt_down : InputEventMouseMotion
|
|
@export var mouse_pan_left : InputEventMouseMotion
|
|
@export var mouse_pan_right : InputEventMouseMotion
|
|
|
|
@export var mouse_movement_speed_up : InputEventMouseButton
|
|
@export var mouse_movement_speed_down : InputEventMouseButton
|
|
|
|
@export_subgroup("Joystick")
|
|
@export var joypad_move_forward : InputEventJoypadMotion
|
|
@export var joypad_move_backward : InputEventJoypadMotion
|
|
@export var joypad_move_left : InputEventJoypadMotion
|
|
@export var joypad_move_right : InputEventJoypadMotion
|
|
@export var joypad_move_up : InputEventJoypadMotion
|
|
@export var joypad_move_down : InputEventJoypadMotion
|
|
|
|
@export var joypad_tilt_up : InputEventJoypadMotion
|
|
@export var joypad_tilt_down : InputEventJoypadMotion
|
|
@export var joypad_pan_left : InputEventJoypadMotion
|
|
@export var joypad_pan_right : InputEventJoypadMotion
|
|
|
|
@export var joypad_movement_speed_up : InputEventJoypadButton
|
|
@export var joypad_movement_speed_down : InputEventJoypadButton
|
|
|
|
@export var joypad_place_marker : InputEventJoypadButton
|
|
@export var joypad_exit_placement : InputEventJoypadButton
|
|
|
|
@onready var input_change_timer : Timer = $InputChangeTimer
|
|
|
|
var stored_mouse_mode : int = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
|
func _enter_tree() -> void:
|
|
get_tree().paused = true
|
|
stored_mouse_mode = Input.mouse_mode
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
InputMap.add_action(&"bugbot_move_forward")
|
|
InputMap.action_add_event(&"bugbot_move_forward", keyboard_move_forward)
|
|
InputMap.action_add_event(&"bugbot_move_forward", joypad_move_forward)
|
|
InputMap.add_action(&"bugbot_move_backward")
|
|
InputMap.action_add_event(&"bugbot_move_backward", keyboard_move_backward)
|
|
InputMap.action_add_event(&"bugbot_move_backward", joypad_move_backward)
|
|
InputMap.add_action(&"bugbot_move_left")
|
|
InputMap.action_add_event(&"bugbot_move_left", keyboard_move_left)
|
|
InputMap.action_add_event(&"bugbot_move_left", joypad_move_left)
|
|
InputMap.add_action(&"bugbot_move_right")
|
|
InputMap.action_add_event(&"bugbot_move_right", keyboard_move_right)
|
|
InputMap.action_add_event(&"bugbot_move_right", joypad_move_right)
|
|
InputMap.add_action(&"bugbot_move_down")
|
|
InputMap.action_add_event(&"bugbot_move_down", keyboard_move_down)
|
|
InputMap.action_add_event(&"bugbot_move_down", joypad_move_down)
|
|
InputMap.add_action(&"bugbot_move_up")
|
|
InputMap.action_add_event(&"bugbot_move_up", keyboard_move_up)
|
|
InputMap.action_add_event(&"bugbot_move_up", joypad_move_up)
|
|
|
|
InputMap.add_action(&"bugbot_tilt_up")
|
|
InputMap.action_add_event(&"bugbot_tilt_up", keyboard_tilt_up)
|
|
InputMap.action_add_event(&"bugbot_tilt_up", joypad_tilt_up)
|
|
InputMap.add_action(&"bugbot_tilt_down")
|
|
InputMap.action_add_event(&"bugbot_tilt_down", keyboard_tilt_down)
|
|
InputMap.action_add_event(&"bugbot_tilt_down", joypad_tilt_down)
|
|
InputMap.add_action(&"bugbot_pan_left")
|
|
InputMap.action_add_event(&"bugbot_pan_left", keyboard_pan_left)
|
|
InputMap.action_add_event(&"bugbot_pan_left", joypad_pan_left)
|
|
InputMap.add_action(&"bugbot_pan_right")
|
|
InputMap.action_add_event(&"bugbot_pan_right", keyboard_pan_right)
|
|
InputMap.action_add_event(&"bugbot_pan_right", joypad_pan_right)
|
|
|
|
InputMap.add_action(&"bugbot_movement_speed_up")
|
|
InputMap.action_add_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
|
InputMap.action_add_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
|
InputMap.action_add_event(&"bugbot_movement_speed_up", joypad_movement_speed_up)
|
|
InputMap.add_action(&"bugbot_movement_speed_down")
|
|
InputMap.action_add_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down)
|
|
InputMap.action_add_event(&"bugbot_movement_speed_down", mouse_movement_speed_down)
|
|
InputMap.action_add_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
|
|
|
func _exit_tree() -> void:
|
|
InputMap.action_erase_event(&"bugbot_move_forward", keyboard_move_forward)
|
|
InputMap.action_erase_event(&"bugbot_move_forward", joypad_move_forward)
|
|
InputMap.action_erase_event(&"bugbot_move_backward", keyboard_move_backward)
|
|
InputMap.action_erase_event(&"bugbot_move_backward", joypad_move_backward)
|
|
InputMap.action_erase_event(&"bugbot_move_left", keyboard_move_left)
|
|
InputMap.action_erase_event(&"bugbot_move_left", joypad_move_left)
|
|
InputMap.action_erase_event(&"bugbot_move_right", keyboard_move_right)
|
|
InputMap.action_erase_event(&"bugbot_move_right", joypad_move_right)
|
|
InputMap.action_erase_event(&"bugbot_move_down", keyboard_move_down)
|
|
InputMap.action_erase_event(&"bugbot_move_down", joypad_move_down)
|
|
InputMap.action_erase_event(&"bugbot_move_up", keyboard_move_up)
|
|
InputMap.action_erase_event(&"bugbot_move_up", joypad_move_up)
|
|
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", keyboard_movement_speed_up)
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", mouse_movement_speed_up)
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_up", joypad_movement_speed_up)
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", keyboard_movement_speed_down)
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", mouse_movement_speed_down)
|
|
InputMap.action_erase_event(&"bugbot_movement_speed_down", joypad_movement_speed_down)
|
|
|
|
Input.mouse_mode = stored_mouse_mode
|
|
get_tree().paused = false
|
|
|
|
|
|
func _process(_delta:float) -> void:
|
|
_calculate_movement_speed()
|
|
|
|
var rotation_velocity : Vector2 = Vector2(
|
|
Input.get_axis(&"bugbot_tilt_down", &"bugbot_tilt_up"),
|
|
Input.get_axis(&"bugbot_pan_right", &"bugbot_pan_left"))
|
|
var mouse_velocity : Vector2 = Input.get_last_mouse_velocity()
|
|
rotation_velocity.x += mouse_velocity.y * -0.0025
|
|
rotation_velocity.y += mouse_velocity.x * -0.0025
|
|
rotation.x = clampf(rotation.x + (rotation_velocity.x * _delta), -PI/2.0 + 0.0001, PI/2.0 - 0.0001)
|
|
rotation.y += rotation_velocity.y * _delta
|
|
|
|
var movement_vector_lateral : Vector2 = Input.get_vector(&"bugbot_move_left", &"bugbot_move_right", &"bugbot_move_forward", &"bugbot_move_backward")
|
|
var movement_azimuth : float = Input.get_axis(&"bugbot_move_down", &"bugbot_move_up")
|
|
velocity = transform.basis * Vector3(movement_vector_lateral.x, movement_azimuth, movement_vector_lateral.y) * movement_speed
|
|
|
|
func _physics_process(_delta:float) -> void:
|
|
move_and_slide()
|
|
|
|
|
|
func _calculate_movement_speed():
|
|
if Input.is_action_pressed(&"bugbot_movement_speed_down") or Input.is_action_just_pressed(&"bugbot_movement_speed_down"):
|
|
if input_change_timer.is_stopped():
|
|
movement_speed -= movement_speed_change_delta
|
|
input_change_timer.start()
|
|
elif Input.is_action_pressed(&"bugbot_movement_speed_up") or Input.is_action_just_pressed(&"bugbot_movement_speed_up"):
|
|
if input_change_timer.is_stopped():
|
|
movement_speed += movement_speed_change_delta
|
|
input_change_timer.start()
|
|
else:
|
|
input_change_timer.stop()
|
|
movement_speed = clampf(movement_speed, 0.25, 50.0)
|