489 lines
17 KiB
GDScript3
Raw Permalink Normal View History

2024-05-28 20:20:10 -07:00
# COPYRIGHT Colormatic Studios
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
# MIT license
2024-05-28 20:20:10 -07:00
# Quality Godot First Person Controller v2
2023-12-01 22:26:46 -08:00
extends CharacterBody3D
2024-05-28 20:23:39 -07:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#region Character Export Group
2024-07-17 17:21:27 -07:00
## The settings for the character's movement and feel.
2023-12-01 22:26:46 -08:00
@export_category("Character")
2024-07-17 17:21:27 -07:00
## The speed that the character moves at without crouching or sprinting.
2023-12-01 22:26:46 -08:00
@export var base_speed : float = 3.0
2024-07-17 17:21:27 -07:00
## The speed that the character moves at when sprinting.
2023-12-01 22:26:46 -08:00
@export var sprint_speed : float = 6.0
2024-07-17 17:21:27 -07:00
## The speed that the character moves at when crouching.
2023-12-01 22:26:46 -08:00
@export var crouch_speed : float = 1.0
2024-07-17 17:21:27 -07:00
## How fast the character speeds up and slows down when Motion Smoothing is on.
2023-12-01 22:26:46 -08:00
@export var acceleration : float = 10.0
2024-07-17 17:21:27 -07:00
## How high the player jumps.
2023-12-01 22:26:46 -08:00
@export var jump_velocity : float = 4.5
2024-07-17 17:21:27 -07:00
## How far the player turns when the mouse is moved.
2023-12-01 22:26:46 -08:00
@export var mouse_sensitivity : float = 0.1
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## Invert the X axis input for the camera.
@export var invert_camera_x_axis : bool = false
## Invert the Y axis input for the camera.
@export var invert_camera_y_axis : bool = false
## Whether the player can use movement inputs. Does not stop outside forces or jumping. See Jumping Enabled.
2024-02-29 19:45:26 -08:00
@export var immobile : bool = false
2024-07-17 17:21:27 -07:00
## The reticle file to import at runtime. By default are in res://addons/fpc/reticles/. Set to an empty string to remove.
2024-03-01 16:02:23 -08:00
@export_file var default_reticle
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
#region Nodes Export Group
2023-12-01 22:26:46 -08:00
@export_group("Nodes")
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the camera for use in the character script. This is the parent node to the camera and is rotated instead of the camera for mouse input.
2023-12-01 22:26:46 -08:00
@export var HEAD : Node3D
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the camera for use in the character script.
2023-12-01 22:26:46 -08:00
@export var CAMERA : Camera3D
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the headbob animation for use in the character script.
2024-01-19 20:31:04 -08:00
@export var HEADBOB_ANIMATION : AnimationPlayer
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the jump animation for use in the character script.
2024-01-19 20:31:04 -08:00
@export var JUMP_ANIMATION : AnimationPlayer
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the crouch animation for use in the character script.
2024-01-20 14:42:32 -08:00
@export var CROUCH_ANIMATION : AnimationPlayer
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## A reference to the the player's collision shape for use in the character script.
@export var COLLISION_MESH : CollisionShape3D
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
#region Controls Export Group
2023-12-01 22:26:46 -08:00
# We are using UI controls because they are built into Godot Engine so they can be used right away
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
@export_group("Controls")
## Use the Input Map to map a mouse/keyboard input to an action and add a reference to it to this dictionary to be used in the script.
@export var controls : Dictionary = {
LEFT = "ui_left",
RIGHT = "ui_right",
FORWARD = "ui_up",
BACKWARD = "ui_down",
JUMP = "ui_accept",
CROUCH = "crouch",
SPRINT = "sprint",
PAUSE = "ui_cancel"
}
@export_subgroup("Controller Specific")
## This only affects how the camera is handled, the rest should be covered by adding controller inputs to the existing actions in the Input Map.
@export var controller_support : bool = false
## Use the Input Map to map a controller input to an action and add a reference to it to this dictionary to be used in the script.
@export var controller_controls : Dictionary = {
LOOK_LEFT = "look_left",
LOOK_RIGHT = "look_right",
LOOK_UP = "look_up",
LOOK_DOWN = "look_down"
}
## The sensitivity of the analog stick that controls camera rotation. Lower is less sensitive and higher is more sensitive.
@export_range(0.001, 1, 0.001) var look_sensitivity : float = 0.035
#endregion
#region Feature Settings Export Group
2023-12-01 22:26:46 -08:00
@export_group("Feature Settings")
2024-07-17 17:21:27 -07:00
## Enable or disable jumping. Useful for restrictive storytelling environments.
2023-12-01 22:26:46 -08:00
@export var jumping_enabled : bool = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## Whether the player can move in the air or not.
2023-12-01 22:26:46 -08:00
@export var in_air_momentum : bool = true
2024-07-17 17:21:27 -07:00
## Smooths the feel of walking.
2023-12-01 22:26:46 -08:00
@export var motion_smoothing : bool = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## Enables or disables sprinting.
2023-12-01 22:26:46 -08:00
@export var sprint_enabled : bool = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## Toggles the sprinting state when button is pressed or requires the player to hold the button down to remain sprinting.
@export_enum("Hold to Sprint", "Toggle Sprint") var sprint_mode : int = 0
## Enables or disables crouching.
2023-12-01 22:26:46 -08:00
@export var crouch_enabled : bool = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## Toggles the crouch state when button is pressed or requires the player to hold the button down to remain crouched.
2023-12-01 22:26:46 -08:00
@export_enum("Hold to Crouch", "Toggle Crouch") var crouch_mode : int = 0
2024-07-17 17:21:27 -07:00
## Wether sprinting should effect FOV.
2023-12-01 22:26:46 -08:00
@export var dynamic_fov : bool = true
2024-07-17 17:21:27 -07:00
## If the player holds down the jump button, should the player keep hopping.
2023-12-01 22:26:46 -08:00
@export var continuous_jumping : bool = true
2024-07-17 17:21:27 -07:00
## Enables the view bobbing animation.
2023-12-01 22:26:46 -08:00
@export var view_bobbing : bool = true
2024-07-17 17:21:27 -07:00
## Enables an immersive animation when the player jumps and hits the ground.
2024-01-19 20:31:04 -08:00
@export var jump_animation : bool = true
2024-07-17 17:21:27 -07:00
## This determines wether the player can use the pause button, not wether the game will actually pause.
2024-03-21 16:02:14 -07:00
@export var pausing_enabled : bool = true
2024-07-17 17:21:27 -07:00
## Use with caution.
2024-05-28 20:21:53 -07:00
@export var gravity_enabled : bool = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
## If your game changes the gravity value during gameplay, check this property to allow the player to experience the change in gravity.
@export var dynamic_gravity : bool = false
2024-05-28 20:21:53 -07:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#region Member Variable Initialization
# These are variables used in this script that don't need to be exposed in the editor.
2023-12-01 22:26:46 -08:00
var speed : float = base_speed
2024-01-20 14:45:12 -08:00
var current_speed : float = 0.0
# States: normal, crouching, sprinting
var state : String = "normal"
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
var low_ceiling : bool = false # This is for when the ceiling is too low and the player needs to crouch.
2024-05-28 20:23:39 -07:00
var was_on_floor : bool = true # Was the player on the floor last frame (for landing animation)
2023-12-01 22:26:46 -08:00
2024-05-28 20:23:39 -07:00
# The reticle should always have a Control node as the root
2024-03-01 16:02:23 -08:00
var RETICLE : Control
2023-12-01 22:26:46 -08:00
# 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
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
# Stores mouse input for rotating the camera in the physics process
2024-07-15 17:24:58 +02:00
var mouseInput : Vector2 = Vector2(0,0)
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
#region Main Control Flow
2023-12-01 22:26:46 -08:00
func _ready():
2024-05-28 20:23:39 -07:00
#It is safe to comment this line if your game doesn't start with the mouse captured
2023-12-01 22:26:46 -08:00
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2024-05-28 20:23:39 -07:00
# If the controller is rotated in a certain direction for game design purposes, redirect this rotation into the head.
2024-05-28 20:24:53 -07:00
HEAD.rotation.y = rotation.y
rotation.y = 0
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2024-03-01 16:02:23 -08:00
if default_reticle:
change_reticle(default_reticle)
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
initialize_animations()
2024-03-21 16:02:14 -07:00
check_controls()
enter_normal_state()
2024-03-21 16:02:14 -07:00
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func _process(_delta):
if pausing_enabled:
handle_pausing()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
update_debug_menu_per_frame()
2024-03-01 16:02:23 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func _physics_process(delta): # Most things happen here.
2023-12-01 22:26:46 -08:00
# Gravity
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if dynamic_gravity:
gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
2024-05-28 20:21:53 -07:00
if not is_on_floor() and gravity and gravity_enabled:
2023-12-01 22:26:46 -08:00
velocity.y -= gravity * delta
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
handle_jumping()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
var input_dir = Vector2.ZERO
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if not immobile: # Immobility works by interrupting user input, so other forces can still be applied to the player
input_dir = Input.get_vector(controls.LEFT, controls.RIGHT, controls.FORWARD, controls.BACKWARD)
2023-12-01 22:26:46 -08:00
handle_movement(delta, input_dir)
2024-07-15 17:24:58 +02:00
handle_head_rotation()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2024-05-28 20:23:39 -07:00
# The player is not able to stand up if the ceiling is too low
low_ceiling = $CrouchCeilingDetection.is_colliding()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
handle_state(input_dir)
2024-05-28 20:23:39 -07:00
if dynamic_fov: # This may be changed to an AnimationPlayer
2023-12-21 21:48:37 -08:00
update_camera_fov()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
if view_bobbing:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
play_headbob_animation(input_dir)
2024-01-19 20:31:04 -08:00
if jump_animation:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
play_jump_animation()
update_debug_menu_per_tick()
2024-05-28 20:23:39 -07:00
was_on_floor = is_on_floor() # This must always be at the end of physics_process
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
#region Input Handling
2023-12-01 22:26:46 -08:00
func handle_jumping():
if jumping_enabled:
2024-05-28 20:23:39 -07:00
if continuous_jumping: # Hold down the jump button
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_pressed(controls.JUMP) and is_on_floor() and !low_ceiling:
2024-01-19 20:31:04 -08:00
if jump_animation:
JUMP_ANIMATION.play("jump", 0.25)
2024-05-28 20:23:39 -07:00
velocity.y += jump_velocity # Adding instead of setting so jumping on slopes works properly
2023-12-01 22:26:46 -08:00
else:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_just_pressed(controls.JUMP) and is_on_floor() and !low_ceiling:
2024-01-19 20:31:04 -08:00
if jump_animation:
JUMP_ANIMATION.play("jump", 0.25)
2023-12-01 22:26:46 -08:00
velocity.y += jump_velocity
2023-12-01 22:26:46 -08:00
func handle_movement(delta, input_dir):
var direction = input_dir.rotated(-HEAD.rotation.y)
direction = Vector3(direction.x, 0, direction.y)
move_and_slide()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
if in_air_momentum:
if is_on_floor():
2023-12-01 22:26:46 -08:00
if motion_smoothing:
velocity.x = lerp(velocity.x, direction.x * speed, acceleration * delta)
velocity.z = lerp(velocity.z, direction.z * speed, acceleration * delta)
else:
velocity.x = direction.x * speed
velocity.z = direction.z * speed
else:
if motion_smoothing:
velocity.x = lerp(velocity.x, direction.x * speed, acceleration * delta)
velocity.z = lerp(velocity.z, direction.z * speed, acceleration * delta)
else:
velocity.x = direction.x * speed
velocity.z = direction.z * speed
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func handle_head_rotation():
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if invert_camera_x_axis:
HEAD.rotation_degrees.y -= mouseInput.x * mouse_sensitivity * -1
else:
HEAD.rotation_degrees.y -= mouseInput.x * mouse_sensitivity
if invert_camera_y_axis:
HEAD.rotation_degrees.x -= mouseInput.y * mouse_sensitivity * -1
else:
HEAD.rotation_degrees.x -= mouseInput.y * mouse_sensitivity
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if controller_support:
var controller_view_rotation = Input.get_vector(controller_controls.LOOK_DOWN, controller_controls.LOOK_UP, controller_controls.LOOK_RIGHT, controller_controls.LOOK_LEFT) * look_sensitivity # These are inverted because of the nature of 3D rotation.
if invert_camera_x_axis:
HEAD.rotation.x += controller_view_rotation.x * -1
else:
HEAD.rotation.x += controller_view_rotation.x
if invert_camera_y_axis:
HEAD.rotation.y += controller_view_rotation.y * -1
else:
HEAD.rotation.y += controller_view_rotation.y
2024-07-15 15:10:44 -07:00
mouseInput = Vector2(0,0)
2024-07-15 17:24:58 +02:00
HEAD.rotation.x = clamp(HEAD.rotation.x, deg_to_rad(-90), deg_to_rad(90))
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func check_controls(): # If you add a control, you might want to add a check for it here.
# The actions are being disabled so the engine doesn't halt the entire project in debug mode
if !InputMap.has_action(controls.JUMP):
push_error("No control mapped for jumping. Please add an input map control. Disabling jump.")
jumping_enabled = false
if !InputMap.has_action(controls.LEFT):
push_error("No control mapped for move left. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(controls.RIGHT):
push_error("No control mapped for move right. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(controls.FORWARD):
push_error("No control mapped for move forward. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(controls.BACKWARD):
push_error("No control mapped for move backward. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(controls.PAUSE):
push_error("No control mapped for pause. Please add an input map control. Disabling pausing.")
pausing_enabled = false
if !InputMap.has_action(controls.CROUCH):
push_error("No control mapped for crouch. Please add an input map control. Disabling crouching.")
crouch_enabled = false
if !InputMap.has_action(controls.SPRINT):
push_error("No control mapped for sprint. Please add an input map control. Disabling sprinting.")
sprint_enabled = false
#endregion
#region State Handling
func handle_state(moving):
if sprint_enabled:
if sprint_mode == 0:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_pressed(controls.SPRINT) and state != "crouching":
if moving:
if state != "sprinting":
enter_sprint_state()
else:
if state == "sprinting":
enter_normal_state()
elif state == "sprinting":
enter_normal_state()
elif sprint_mode == 1:
if moving:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
# If the player is holding sprint before moving, handle that scenario
if Input.is_action_pressed(controls.SPRINT) and state == "normal":
2024-01-20 19:19:13 -08:00
enter_sprint_state()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_just_pressed(controls.SPRINT):
match state:
"normal":
enter_sprint_state()
"sprinting":
enter_normal_state()
elif state == "sprinting":
enter_normal_state()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
if crouch_enabled:
if crouch_mode == 0:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_pressed(controls.CROUCH) and state != "sprinting":
if state != "crouching":
enter_crouch_state()
elif state == "crouching" and !$CrouchCeilingDetection.is_colliding():
enter_normal_state()
2023-12-01 22:26:46 -08:00
elif crouch_mode == 1:
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
if Input.is_action_just_pressed(controls.CROUCH):
match state:
"normal":
enter_crouch_state()
"crouching":
if !$CrouchCeilingDetection.is_colliding():
enter_normal_state()
2024-01-09 13:57:39 -08:00
# Any enter state function should only be called once when you want to enter that state, not every frame.
func enter_normal_state():
#print("entering normal state")
var prev_state = state
2024-01-20 14:42:32 -08:00
if prev_state == "crouching":
CROUCH_ANIMATION.play_backwards("crouch")
state = "normal"
speed = base_speed
func enter_crouch_state():
#print("entering crouch state")
state = "crouching"
speed = crouch_speed
2024-01-20 14:42:32 -08:00
CROUCH_ANIMATION.play("crouch")
func enter_sprint_state():
#print("entering sprint state")
var prev_state = state
2024-01-20 14:42:32 -08:00
if prev_state == "crouching":
CROUCH_ANIMATION.play_backwards("crouch")
state = "sprinting"
speed = sprint_speed
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#region Animation Handling
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func initialize_animations():
# Reset the camera position
# If you want to change the default head height, change these animations.
HEADBOB_ANIMATION.play("RESET")
JUMP_ANIMATION.play("RESET")
CROUCH_ANIMATION.play("RESET")
2023-12-01 22:26:46 -08:00
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func play_headbob_animation(moving):
2023-12-01 22:26:46 -08:00
if moving and is_on_floor():
2024-02-29 19:36:50 -08:00
var use_headbob_animation : String
match state:
"normal","crouching":
use_headbob_animation = "walk"
"sprinting":
use_headbob_animation = "sprint"
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
var was_playing : bool = false
2024-02-29 19:36:50 -08:00
if HEADBOB_ANIMATION.current_animation == use_headbob_animation:
was_playing = true
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2024-02-29 19:36:50 -08:00
HEADBOB_ANIMATION.play(use_headbob_animation, 0.25)
2024-01-20 14:45:12 -08:00
HEADBOB_ANIMATION.speed_scale = (current_speed / base_speed) * 1.75
if !was_playing:
HEADBOB_ANIMATION.seek(float(randi() % 2)) # Randomize the initial headbob direction
# Let me explain that piece of code because it looks like it does the opposite of what it actually does.
# The headbob animation has two starting positions. One is at 0 and the other is at 1.
# randi() % 2 returns either 0 or 1, and so the animation randomly starts at one of the starting positions.
2024-02-29 19:36:50 -08:00
# This code is extremely performant but it makes no sense.
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
2023-12-01 22:26:46 -08:00
else:
if HEADBOB_ANIMATION.current_animation == "sprint" or HEADBOB_ANIMATION.current_animation == "walk":
HEADBOB_ANIMATION.speed_scale = 1
HEADBOB_ANIMATION.play("RESET", 1)
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func play_jump_animation():
if !was_on_floor and is_on_floor(): # The player just landed
var facing_direction : Vector3 = CAMERA.get_global_transform().basis.x
var facing_direction_2D : Vector2 = Vector2(facing_direction.x, facing_direction.z).normalized()
var velocity_2D : Vector2 = Vector2(velocity.x, velocity.z).normalized()
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
# Compares velocity direction against the camera direction (via dot product) to determine which landing animation to play.
var side_landed : int = round(velocity_2D.dot(facing_direction_2D))
if side_landed > 0:
JUMP_ANIMATION.play("land_right", 0.25)
elif side_landed < 0:
JUMP_ANIMATION.play("land_left", 0.25)
else:
JUMP_ANIMATION.play("land_center", 0.25)
#endregion
#region Debug Menu
func update_debug_menu_per_frame():
$UserInterface/DebugPanel.add_property("FPS", Performance.get_monitor(Performance.TIME_FPS), 0)
var status : String = state
if !is_on_floor():
status += " in the air"
2024-01-20 14:45:12 -08:00
$UserInterface/DebugPanel.add_property("State", status, 4)
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
func update_debug_menu_per_tick():
# Big thanks to github.com/LorenzoAncora for the concept of the improved debug values
current_speed = Vector3.ZERO.distance_to(get_real_velocity())
$UserInterface/DebugPanel.add_property("Speed", snappedf(current_speed, 0.001), 1)
$UserInterface/DebugPanel.add_property("Target speed", speed, 2)
var cv : Vector3 = get_real_velocity()
var vd : Array[float] = [
snappedf(cv.x, 0.001),
snappedf(cv.y, 0.001),
snappedf(cv.z, 0.001)
]
var readable_velocity : String = "X: " + str(vd[0]) + " Y: " + str(vd[1]) + " Z: " + str(vd[2])
$UserInterface/DebugPanel.add_property("Velocity", readable_velocity, 3)
func _unhandled_input(event : InputEvent):
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
2024-07-15 17:24:58 +02:00
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
Various enhancements, fixes, and tweaks focused on improving the inspector (#34) * Added Dynamic Gravity Toggle Added an editor toggle for dynamic gravity so users don't need to uncomment code in character.gd. * Refactor controls export variables Changed controls export variables to be a single dictionary so they can be edited completely in the editor without having to open the script. I also refactored the controller support section to allow similar functionality for controller specific controls and removed the need to uncomment/comment out lines of code to turn on/off controller support. * Add more editor descriptions and implement camera axis inversion options Added/tweaked export variable descriptions so everything has one. Also slightly refactored the camera input inversion code and added the ability to invert the camera x axis. * Added direction based landing animations Added some logic to determine which landing animation to play so it's not random anymore. Also added a land_center animation for the case of neutral landings. This can be expanded if desired, but it's pretty convincing as is and is ulitmately a small detail. * Correct various grammar and spelling errors A final pass to clean up any grammatical or spelling errors in the comments * Re-organized Character.gd Hope I'm not overstepping here, but I re-organized Character.gd to make it a bit easier to read and work with. Added editor bookmarks and collapsible code regions. It's hard to parse in the diff so I recommend you look at it in Godot proper. * Commented out debug print statement I assume this was left uncommented by mistake. I was wondering what was printing that to my console. * Fixed Landing Animation Logic I guess I was up too late on my first attempt because it straight up didn't work. This new version works as far as my testing can tell. * Removed some unused variables
2024-10-25 16:30:03 -04:00
#endregion
#region Misc Functions
func change_reticle(reticle): # Yup, this function is kinda strange
if RETICLE:
RETICLE.queue_free()
RETICLE = load(reticle).instantiate()
RETICLE.character = self
$UserInterface.add_child(RETICLE)
func update_camera_fov():
if state == "sprinting":
CAMERA.fov = lerp(CAMERA.fov, 85.0, 0.3)
else:
CAMERA.fov = lerp(CAMERA.fov, 75.0, 0.3)
func handle_pausing():
if Input.is_action_just_pressed(controls.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
#endregion