25 Commits
2.5 ... 2.6

Author SHA1 Message Date
Zakarya
b57da3669c fix README 3 2024-08-20 18:27:22 -07:00
Zakarya
e45406d35c fix README 2 2024-08-20 18:26:05 -07:00
Zakarya
7ace3c48b8 fix README 2024-08-20 18:24:39 -07:00
Zakarya
54a07cc6cf Slope/staircase guide 2024-08-20 18:23:22 -07:00
0e2a12ce5c Fix head rotation 2024-07-24 11:35:05 -07:00
aef3c9c0f9 Fixup #25
Make the PR code more readable and match the style of the codebase
2024-07-24 11:29:38 -07:00
3567b157c0 Improve editor module 2024-07-23 20:18:20 -07:00
6c719b52cc Add a toggle button for the debug panel and clean up some comments 2024-07-23 20:18:20 -07:00
Zakarya
7009032757 Merge pull request #25 from DanielKinsman/invert_pitch
Option to invert mouse/joystick y axis (pitch)
2024-07-23 19:03:48 -07:00
Daniel Kinsman
40f5d21452 Option to invert mouse/joystick y axis (pitch) 2024-07-24 11:31:18 +10:00
14a3fb15f0 Remove hardcoded controller sensitivity 2024-07-17 17:25:17 -07:00
bd603973d0 Add descriptions for exported values 2024-07-17 17:21:27 -07:00
a8d151d568 Add controller support to PR #22 2024-07-15 15:10:44 -07:00
b458cba1a1 Rename handle_rotation to handle_head_rotation 2024-07-15 15:10:20 -07:00
Zakarya
4782f80ec2 Merge pull request #22 from Knockturnal/main
Fixed camera jitter
2024-07-15 14:52:49 -07:00
Knockturnal
8a398bade0 Fixed camera jitter 2024-07-15 17:24:58 +02:00
28becd88c2 Set default values for crouch and sprint in the script 2024-07-02 08:56:27 -07:00
Zakarya
1f9bbd73b3 Merge pull request #20 from Phlegmlee/main
Removed hardcoded lines (causing the sprint and crouch bug) from Character.tscn
2024-07-02 08:55:18 -07:00
Tanner
4c0152e688 Merge branch 'ColormaticStudios:main' into main 2024-07-01 22:04:16 -06:00
Tanner
2d654f7600 Remove hard coded lines
Removed the hard coded lines that were causing the sprint and crouch variables to initialize to lowercase "crouch" and "sprint" instead of user specified values in the script.
2024-07-01 22:03:30 -06:00
6257f07766 Add a comment for check_controls 2024-07-01 19:52:49 -07:00
Zakarya
6a6de243dd Merge pull request #19 from Phlegmlee/main
Removed a stray word in the pause error message.
2024-07-01 19:47:09 -07:00
Tanner
669c951a81 Remove stray word in error message
Removed the word "move" from the error statement referring to the action PAUSE.
2024-07-01 19:55:15 -06:00
c64deaa27a Remove an accidental printf debug
I had added this here to find out why the  headbob animation reset
without any smoothing, but didn't realize it was there in the latest
commit.
2024-07-01 17:15:56 -07:00
be0001e554 Reset a RESET value, attempt to fix a camera bug 2024-06-21 00:11:36 -07:00
5 changed files with 95 additions and 85 deletions

View File

@ -33,9 +33,13 @@ You can make this a super basic controller by just disabling everything.
- In the controls export group, there is a commented section at the end that says "Uncomment this if you want full controller support". Uncomment that block.
- Make a key map for each direction (left, right, up, down) and map them to your joystick.
- Write in these keymaps in the controls section of the player settings.
- In the `_process` function, there is another block of commented code at the end that says the same thing. Uncomment that too.
- In the `handle_head_rotation` function, there is another block of commented code that says the same thing. Uncomment that too.
- You should now be able to look around with the joystick. Make sure you add the other controls to the input map. (movement, jumping, crouching, sprinting, etc.)
**Slope/staircase:**
Credit to @roberto-urbani23
In the character inspector, you can uncheck Stop on Slope and set the max angle to 89 (for some reason, 90 will make the player stuck). Also Snap Length to 1 otherwise your character will not remain attached to stairs if you sprint while going downstairs.
**How to change settings:**
Click on the character node and there should be settings in the "Feature Settings" group.

View File

@ -1,39 +1,40 @@
@tool
extends Node
# This module affects runtime nad
# This does not effect runtime yet but will in the future.
#TODO: Add descriptions
@export_category("Controller Editor Module")
@export var head_y_rotation : float = 0:
@export_range(-360.0, 360.0, 0.01, "or_greater", "or_less") var head_y_rotation : float = 0.0:
set(new_rotation):
head_y_rotation = new_rotation
HEAD.rotation.y = head_y_rotation
update_configuration_warnings()
if HEAD:
head_y_rotation = new_rotation
HEAD.rotation.y = deg_to_rad(head_y_rotation)
update_configuration_warnings()
@export_range(-90.0, 90.0, 0.01, "or_greater", "or_less") var head_x_rotation : float = 0.0:
set(new_rotation):
if HEAD:
head_x_rotation = new_rotation
HEAD.rotation.x = deg_to_rad(head_x_rotation)
update_configuration_warnings()
@export_group("Nodes")
@export var CHARACTER : CharacterBody3D
@export var head_path : String = "Head" # From this nodes parent node
@export var head_path : String = "Head" # Relative to the parent node
#@export var CAMERA : Camera3D
#@export var HEADBOB_ANIMATION : AnimationPlayer
#@export var JUMP_ANIMATION : AnimationPlayer
#@export var CROUCH_ANIMATION : AnimationPlayer
#@export var COLLISION_MESH : CollisionShape3D
var HEAD
@onready var HEAD = get_node("../" + head_path)
func _ready():
HEAD = get_node("../" + head_path)
if Engine.is_editor_hint():
pass
else:
HEAD.rotation.y = head_y_rotation
if !Engine.is_editor_hint():
print("not editor")
HEAD.rotation.y = deg_to_rad(head_y_rotation)
HEAD.rotation.x = deg_to_rad(head_x_rotation)
func _process(delta):
if Engine.is_editor_hint():
pass
func _get_configuration_warnings():
var warnings = []
@ -41,8 +42,8 @@ func _get_configuration_warnings():
if head_y_rotation > 360:
warnings.append("The head rotation is greater than 360")
if head_y_rotation < 0:
warnings.append("The head rotation is less than 0")
if head_y_rotation < -360:
warnings.append("The head rotation is less than -360")
# Returning an empty array gives no warnings
return warnings

View File

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

View File

@ -174,17 +174,6 @@ tracks/1/keys = {
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
tracks/2/type = "bezier"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Camera:position:z")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"handle_modes": PackedInt32Array(0),
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0)
}
[sub_resource type="Animation" id="Animation_8ku67"]
resource_name = "sprint"
@ -212,17 +201,6 @@ tracks/1/keys = {
"points": PackedFloat32Array(0.05, -0.25, 0, 0.2, -0.01, 0, -0.2, 0.000186046, 0.2, 0.000186046, 0.05, -0.2, -0.01, 0.2, -0.01, 0, -0.2, 0, 0.2, 0, 0.05, -0.2, -0.01, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
tracks/2/type = "bezier"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Camera:position:z")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0),
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
[sub_resource type="Animation" id="Animation_lrqmv"]
resource_name = "walk"
@ -250,17 +228,6 @@ tracks/1/keys = {
"points": PackedFloat32Array(-0.05, -0.25, 0, 0.2, 0.005, 0, -0.2, 0.000186046, 0.2, 0.000186046, -0.05, -0.2, 0.005, 0.2, 0.005, 0, -0.2, 0, 0.2, 0, -0.05, -0.2, 0.005, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
tracks/2/type = "bezier"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Camera:position:z")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0),
"points": PackedFloat32Array(0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_o0unb"]
_data = {
@ -281,7 +248,7 @@ tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Vector3(0.0349066, 0, 0)]
"values": [Vector3(0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
@ -393,8 +360,6 @@ HEADBOB_ANIMATION = NodePath("Head/HeadbobAnimation")
JUMP_ANIMATION = NodePath("Head/JumpAnimation")
CROUCH_ANIMATION = NodePath("CrouchAnimation")
COLLISION_MESH = NodePath("Collision")
CROUCH = "crouch"
SPRINT = "sprint"
[node name="Mesh" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
@ -413,7 +378,6 @@ libraries = {
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="Camera" type="Camera3D" parent="Head"]
transform = Transform3D(1, 0, 0, 0, 0.999391, -0.0348995, 0, 0.0348995, 0.999391, 0, 0, 0)
[node name="HeadbobAnimation" type="AnimationPlayer" parent="Head"]
libraries = {

View File

@ -65,9 +65,6 @@ uv1_triplanar_sharpness = 0.000850145
[node name="Character" parent="." instance=ExtResource("1_e18vq")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
[node name="Camera" parent="Character/Head" index="0"]
transform = Transform3D(1, 0, 0, 0, 0.999391, -0.0348995, 0, 0.0348995, 0.999391, 0, 0, 0)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_20rw3")
@ -107,5 +104,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.5, 3, -15.5)
use_collision = true
size = Vector3(19, 8, 1)
material = SubResource("StandardMaterial3D_7j4uu")
[editable path="Character"]