- Adjusted movement speed calculation to be much closer to how Godot handles it in editor.

- Added a much smaller deadzone for all movement axes.
This commit is contained in:
Jamie Greunbaum 2024-05-14 00:15:49 -04:00
parent 9ab5751fac
commit b3dbe0d72c

View File

@ -1,9 +1,5 @@
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
@ -54,6 +50,8 @@ extends CharacterBody3D
@onready var input_change_timer : Timer = $InputChangeTimer
var movement_speed : float = 5.0
var stored_mouse_mode : int = Input.MOUSE_MODE_CAPTURED
@ -62,35 +60,35 @@ func _enter_tree() -> void:
stored_mouse_mode = Input.mouse_mode
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
InputMap.add_action(&"bugbot_move_forward")
InputMap.add_action(&"bugbot_move_forward", 0.1)
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.add_action(&"bugbot_move_backward", 0.1)
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.add_action(&"bugbot_move_left", 0.1)
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.add_action(&"bugbot_move_right", 0.1)
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.add_action(&"bugbot_move_down", 0.1)
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.add_action(&"bugbot_move_up", 0.1)
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.add_action(&"bugbot_tilt_up", 0.1)
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.add_action(&"bugbot_tilt_down", 0.1)
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.add_action(&"bugbot_pan_left", 0.1)
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.add_action(&"bugbot_pan_right", 0.1)
InputMap.action_add_event(&"bugbot_pan_right", keyboard_pan_right)
InputMap.action_add_event(&"bugbot_pan_right", joypad_pan_right)
@ -133,7 +131,7 @@ func _process(_delta:float) -> void:
var rotation_velocity : Vector2 = Vector2(
Input.get_axis(&"bugbot_tilt_down", &"bugbot_tilt_up"),
Input.get_axis(&"bugbot_pan_right", &"bugbot_pan_left"))
Input.get_axis(&"bugbot_pan_right", &"bugbot_pan_left")) * 2.5
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
@ -151,11 +149,11 @@ func _physics_process(_delta:float) -> void:
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
movement_speed /= 1.2
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
movement_speed *= 1.2
input_change_timer.start()
else:
input_change_timer.stop()