|
|
|
@ -6,21 +6,31 @@
|
|
|
|
|
|
|
|
|
|
extends CharacterBody3D
|
|
|
|
|
|
|
|
|
|
# TODO: Add descriptions for each value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The settings for the character's movement and feel.
|
|
|
|
|
@export_category("Character")
|
|
|
|
|
## The speed that the character moves at without crouching or sprinting.
|
|
|
|
|
@export var base_speed : float = 3.0
|
|
|
|
|
## The speed that the character moves at when sprinting.
|
|
|
|
|
@export var sprint_speed : float = 6.0
|
|
|
|
|
## The speed that the character moves at when crouching.
|
|
|
|
|
@export var crouch_speed : float = 1.0
|
|
|
|
|
|
|
|
|
|
## How fast the character speeds up and slows down when Motion Smoothing is on.
|
|
|
|
|
@export var acceleration : float = 10.0
|
|
|
|
|
## How high the player jumps.
|
|
|
|
|
@export var jump_velocity : float = 4.5
|
|
|
|
|
## How far the player turns when the mouse is moved.
|
|
|
|
|
@export var mouse_sensitivity : float = 0.1
|
|
|
|
|
## Invert the Y input for mouse and joystick
|
|
|
|
|
@export var invert_mouse_y : bool = false # Possibly add an invert mouse X in the future
|
|
|
|
|
## Wether the player can use movement inputs. Does not stop outside forces or jumping. See Jumping Enabled.
|
|
|
|
|
@export var immobile : bool = false
|
|
|
|
|
## The reticle file to import at runtime. By default are in res://addons/fpc/reticles/. Set to an empty string to remove.
|
|
|
|
|
@export_file var default_reticle
|
|
|
|
|
|
|
|
|
|
@export_group("Nodes")
|
|
|
|
|
## The node that holds the camera. This is rotated instead of the camera for mouse input.
|
|
|
|
|
@export var HEAD : Node3D
|
|
|
|
|
@export var CAMERA : Camera3D
|
|
|
|
|
@export var HEADBOB_ANIMATION : AnimationPlayer
|
|
|
|
@ -35,29 +45,40 @@ extends CharacterBody3D
|
|
|
|
|
@export var RIGHT : String = "ui_right"
|
|
|
|
|
@export var FORWARD : String = "ui_up"
|
|
|
|
|
@export var BACKWARD : String = "ui_down"
|
|
|
|
|
## By default this does not pause the game, but that can be changed in _process.
|
|
|
|
|
@export var PAUSE : String = "ui_cancel"
|
|
|
|
|
@export var CROUCH : String = "crouch"
|
|
|
|
|
@export var SPRINT : String = "sprint"
|
|
|
|
|
|
|
|
|
|
# Uncomment if you want full controller support
|
|
|
|
|
#@export var LOOK_LEFT : String
|
|
|
|
|
#@export var LOOK_RIGHT : String
|
|
|
|
|
#@export var LOOK_UP : String
|
|
|
|
|
#@export var LOOK_DOWN : String
|
|
|
|
|
# Uncomment if you want controller support
|
|
|
|
|
#@export var controller_sensitivity : float = 0.035
|
|
|
|
|
#@export var LOOK_LEFT : String = "look_left"
|
|
|
|
|
#@export var LOOK_RIGHT : String = "look_right"
|
|
|
|
|
#@export var LOOK_UP : String = "look_up"
|
|
|
|
|
#@export var LOOK_DOWN : String = "look_down"
|
|
|
|
|
|
|
|
|
|
@export_group("Feature Settings")
|
|
|
|
|
## Enable or disable jumping. Useful for restrictive storytelling environments.
|
|
|
|
|
@export var jumping_enabled : bool = true
|
|
|
|
|
## Wether the player can move in the air or not.
|
|
|
|
|
@export var in_air_momentum : bool = true
|
|
|
|
|
## Smooths the feel of walking.
|
|
|
|
|
@export var motion_smoothing : bool = true
|
|
|
|
|
@export var sprint_enabled : bool = true
|
|
|
|
|
@export var crouch_enabled : bool = true
|
|
|
|
|
@export_enum("Hold to Crouch", "Toggle Crouch") var crouch_mode : int = 0
|
|
|
|
|
@export_enum("Hold to Sprint", "Toggle Sprint") var sprint_mode : int = 0
|
|
|
|
|
## Wether sprinting should effect FOV.
|
|
|
|
|
@export var dynamic_fov : bool = true
|
|
|
|
|
## If the player holds down the jump button, should the player keep hopping.
|
|
|
|
|
@export var continuous_jumping : bool = true
|
|
|
|
|
## Enables the view bobbing animation.
|
|
|
|
|
@export var view_bobbing : bool = true
|
|
|
|
|
## Enables an immersive animation when the player jumps and hits the ground.
|
|
|
|
|
@export var jump_animation : bool = true
|
|
|
|
|
## This determines wether the player can use the pause button, not wether the game will actually pause.
|
|
|
|
|
@export var pausing_enabled : bool = true
|
|
|
|
|
## Use with caution.
|
|
|
|
|
@export var gravity_enabled : bool = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -75,6 +96,8 @@ var RETICLE : Control
|
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes
|
|
|
|
|
var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity") # Don't set this as a const, see the gravity section in _physics_process
|
|
|
|
|
|
|
|
|
|
# Stores mouse input for rotating the camera in the phyhsics process
|
|
|
|
|
var mouseInput : Vector2 = Vector2(0,0)
|
|
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
|
#It is safe to comment this line if your game doesn't start with the mouse captured
|
|
|
|
@ -158,6 +181,8 @@ func _physics_process(delta):
|
|
|
|
|
input_dir = Input.get_vector(LEFT, RIGHT, FORWARD, BACKWARD)
|
|
|
|
|
handle_movement(delta, input_dir)
|
|
|
|
|
|
|
|
|
|
handle_head_rotation()
|
|
|
|
|
|
|
|
|
|
# The player is not able to stand up if the ceiling is too low
|
|
|
|
|
low_ceiling = $CrouchCeilingDetection.is_colliding()
|
|
|
|
|
|
|
|
|
@ -214,6 +239,25 @@ func handle_movement(delta, input_dir):
|
|
|
|
|
velocity.x = direction.x * speed
|
|
|
|
|
velocity.z = direction.z * speed
|
|
|
|
|
|
|
|
|
|
func handle_head_rotation():
|
|
|
|
|
HEAD.rotation_degrees.y -= mouseInput.x * mouse_sensitivity
|
|
|
|
|
if invert_mouse_y:
|
|
|
|
|
HEAD.rotation_degrees.x -= mouseInput.y * mouse_sensitivity * -1.0
|
|
|
|
|
else:
|
|
|
|
|
HEAD.rotation_degrees.x -= mouseInput.y * mouse_sensitivity
|
|
|
|
|
|
|
|
|
|
# Uncomment for controller support
|
|
|
|
|
#var controller_view_rotation = Input.get_vector(LOOK_DOWN, LOOK_UP, LOOK_RIGHT, LOOK_LEFT) * controller_sensitivity # These are inverted because of the nature of 3D rotation.
|
|
|
|
|
#HEAD.rotation.x += controller_view_rotation.x
|
|
|
|
|
#if invert_mouse_y:
|
|
|
|
|
#HEAD.rotation.y += controller_view_rotation.y * -1.0
|
|
|
|
|
#else:
|
|
|
|
|
#HEAD.rotation.y += controller_view_rotation.y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mouseInput = Vector2(0,0)
|
|
|
|
|
HEAD.rotation.x = clamp(HEAD.rotation.x, deg_to_rad(-90), deg_to_rad(90))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func handle_state(moving):
|
|
|
|
|
if sprint_enabled:
|
|
|
|
@ -328,22 +372,23 @@ func _process(delta):
|
|
|
|
|
|
|
|
|
|
if pausing_enabled:
|
|
|
|
|
if Input.is_action_just_pressed(PAUSE):
|
|
|
|
|
# You may want another node to handle pausing, because this player may get paused too.
|
|
|
|
|
match Input.mouse_mode:
|
|
|
|
|
Input.MOUSE_MODE_CAPTURED:
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
|
|
|
#get_tree().paused = false
|
|
|
|
|
Input.MOUSE_MODE_VISIBLE:
|
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
|
#get_tree().paused = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HEAD.rotation.x = clamp(HEAD.rotation.x, deg_to_rad(-90), deg_to_rad(90))
|
|
|
|
|
|
|
|
|
|
# Uncomment if you want full controller support
|
|
|
|
|
#var controller_view_rotation = Input.get_vector(LOOK_LEFT, LOOK_RIGHT, LOOK_UP, LOOK_DOWN)
|
|
|
|
|
#HEAD.rotation_degrees.y -= controller_view_rotation.x * 1.5
|
|
|
|
|
#HEAD.rotation_degrees.x -= controller_view_rotation.y * 1.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
|
func _unhandled_input(event : InputEvent):
|
|
|
|
|
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
|
|
|
|
HEAD.rotation_degrees.y -= event.relative.x * mouse_sensitivity
|
|
|
|
|
HEAD.rotation_degrees.x -= event.relative.y * mouse_sensitivity
|
|
|
|
|
mouseInput.x += event.relative.x
|
|
|
|
|
mouseInput.y += event.relative.y
|
|
|
|
|
# Toggle debug menu
|
|
|
|
|
elif event is InputEventKey:
|
|
|
|
|
if event.is_released():
|
|
|
|
|
# Where we're going, we don't need InputMap
|
|
|
|
|
if event.keycode == 4194338: # F7
|
|
|
|
|
$UserInterface/DebugPanel.visible = !$UserInterface/DebugPanel.visible
|
|
|
|
|