3 Commits
2.4 ... 2.4.1

2 changed files with 171 additions and 144 deletions

View File

@ -13,8 +13,6 @@ extends CharacterBody3D
@export var immobile : bool = false @export var immobile : bool = false
@export_file var default_reticle @export_file var default_reticle
@export var initial_facing_direction : Vector3 = Vector3.ZERO
@export_group("Nodes") @export_group("Nodes")
@export var HEAD : Node3D @export var HEAD : Node3D
@export var CAMERA : Camera3D @export var CAMERA : Camera3D
@ -52,6 +50,7 @@ extends CharacterBody3D
@export var continuous_jumping : bool = true @export var continuous_jumping : bool = true
@export var view_bobbing : bool = true @export var view_bobbing : bool = true
@export var jump_animation : bool = true @export var jump_animation : bool = true
@export var pausing_enabled : bool = true
# Member variables # Member variables
var speed : float = base_speed var speed : float = base_speed
@ -70,9 +69,8 @@ var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity")
func _ready(): func _ready():
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
# Set the camera rotation to whatever initial_facing_direction is HEAD.rotation = rotation
if initial_facing_direction: rotation = Vector3.ZERO
HEAD.set_rotation_degrees(initial_facing_direction) # I don't want to be calling this function if the vector is zero
if default_reticle: if default_reticle:
change_reticle(default_reticle) change_reticle(default_reticle)
@ -82,6 +80,34 @@ func _ready():
JUMP_ANIMATION.play("RESET") JUMP_ANIMATION.play("RESET")
CROUCH_ANIMATION.play("RESET") CROUCH_ANIMATION.play("RESET")
check_controls()
func check_controls(): # If you add a control, you might want to add a check for it here.
if !InputMap.has_action(JUMP):
push_error("No control mapped for jumping. Please add an input map control. Disabling jump.")
jumping_enabled = false
if !InputMap.has_action(LEFT):
push_error("No control mapped for move left. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(RIGHT):
push_error("No control mapped for move right. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(FORWARD):
push_error("No control mapped for move forward. Please add an input map control. Disabling movement.")
immobile = true
if !InputMap.has_action(BACKWARD):
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.")
pausing_enabled = false
if !InputMap.has_action(CROUCH):
push_error("No control mapped for crouch. Please add an input map control. Disabling crouching.")
crouch_enabled = false
if !InputMap.has_action(SPRINT):
push_error("No control mapped for sprint. Please add an input map control. Disabling sprinting.")
sprint_enabled = false
func change_reticle(reticle): func change_reticle(reticle):
if RETICLE: if RETICLE:
@ -130,9 +156,9 @@ func _physics_process(delta):
if !was_on_floor and is_on_floor(): # Just landed if !was_on_floor and is_on_floor(): # Just landed
match randi() % 2: match randi() % 2:
0: 0:
JUMP_ANIMATION.play("land_left") JUMP_ANIMATION.play("land_left", 0.25)
1: 1:
JUMP_ANIMATION.play("land_right") JUMP_ANIMATION.play("land_right", 0.25)
was_on_floor = is_on_floor() # This must always be at the end of physics_process was_on_floor = is_on_floor() # This must always be at the end of physics_process
@ -142,12 +168,12 @@ func handle_jumping():
if continuous_jumping: if continuous_jumping:
if Input.is_action_pressed(JUMP) and is_on_floor() and !low_ceiling: if Input.is_action_pressed(JUMP) and is_on_floor() and !low_ceiling:
if jump_animation: if jump_animation:
JUMP_ANIMATION.play("jump") JUMP_ANIMATION.play("jump", 0.25)
velocity.y += jump_velocity velocity.y += jump_velocity
else: else:
if Input.is_action_just_pressed(JUMP) and is_on_floor() and !low_ceiling: if Input.is_action_just_pressed(JUMP) and is_on_floor() and !low_ceiling:
if jump_animation: if jump_animation:
JUMP_ANIMATION.play("jump") JUMP_ANIMATION.play("jump", 0.25)
velocity.y += jump_velocity velocity.y += jump_velocity
@ -283,6 +309,7 @@ func _process(delta):
status += " in the air" status += " in the air"
$UserInterface/DebugPanel.add_property("State", status, 4) $UserInterface/DebugPanel.add_property("State", status, 4)
if pausing_enabled:
if Input.is_action_just_pressed(PAUSE): if Input.is_action_just_pressed(PAUSE):
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED: if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE Input.mouse_mode = Input.MOUSE_MODE_VISIBLE

View File

@ -13,70 +13,6 @@ material = SubResource("StandardMaterial3D_kp17n")
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_uy03j"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_uy03j"]
[sub_resource type="Animation" id="Animation_5ec5e"]
resource_name = "crouch"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Mesh:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1, 0.75, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Collision:scale")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1, 0.75, 1)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Mesh:position")
tracks/2/interp = 2
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("Collision:position")
tracks/3/interp = 2
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)]
}
tracks/4/type = "value"
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/path = NodePath("Head:position")
tracks/4/interp = 2
tracks/4/loop_wrap = true
tracks/4/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1.5, 0), Vector3(0, 1.12508, 0)]
}
[sub_resource type="Animation" id="Animation_j8cx7"] [sub_resource type="Animation" id="Animation_j8cx7"]
resource_name = "RESET" resource_name = "RESET"
length = 0.001 length = 0.001
@ -141,6 +77,70 @@ tracks/4/keys = {
"values": [Vector3(0, 1.5, 0)] "values": [Vector3(0, 1.5, 0)]
} }
[sub_resource type="Animation" id="Animation_5ec5e"]
resource_name = "crouch"
length = 0.2
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Mesh:scale")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1, 0.75, 1)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Collision:scale")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(1, 1, 1), Vector3(1, 0.75, 1)]
}
tracks/2/type = "value"
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/path = NodePath("Mesh:position")
tracks/2/interp = 2
tracks/2/loop_wrap = true
tracks/2/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)]
}
tracks/3/type = "value"
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/path = NodePath("Collision:position")
tracks/3/interp = 2
tracks/3/loop_wrap = true
tracks/3/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)]
}
tracks/4/type = "value"
tracks/4/imported = false
tracks/4/enabled = true
tracks/4/path = NodePath("Head:position")
tracks/4/interp = 2
tracks/4/loop_wrap = true
tracks/4/keys = {
"times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Vector3(0, 1.5, 0), Vector3(0, 1.12508, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5e5t5"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_5e5t5"]
_data = { _data = {
"RESET": SubResource("Animation_j8cx7"), "RESET": SubResource("Animation_j8cx7"),
@ -185,44 +185,6 @@ tracks/2/keys = {
"times": PackedFloat32Array(0) "times": PackedFloat32Array(0)
} }
[sub_resource type="Animation" id="Animation_lrqmv"]
resource_name = "walk"
length = 2.0
loop_mode = 1
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera:position:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 1, 0, 1, 0),
"points": PackedFloat32Array(0.04, -0.25, 0, 0.25, 0, 0, 0, 0, 0, 0, -0.04, -0.25, 0, 0.25, 0, 0, 0, 0, 0, 0, 0.04, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Camera:position:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0),
"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="Animation" id="Animation_8ku67"] [sub_resource type="Animation" id="Animation_8ku67"]
resource_name = "sprint" resource_name = "sprint"
length = 2.0 length = 2.0
@ -261,6 +223,44 @@ tracks/2/keys = {
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2) "times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
} }
[sub_resource type="Animation" id="Animation_lrqmv"]
resource_name = "walk"
length = 2.0
loop_mode = 1
tracks/0/type = "bezier"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera:position:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 1, 0, 1, 0),
"points": PackedFloat32Array(0.04, -0.25, 0, 0.25, 0, 0, 0, 0, 0, 0, -0.04, -0.25, 0, 0.25, 0, 0, 0, 0, 0, 0, 0.04, -0.25, 0, 0.25, 0),
"times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
}
tracks/1/type = "bezier"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Camera:position:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0),
"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"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_o0unb"]
_data = { _data = {
"RESET": SubResource("Animation_gh776"), "RESET": SubResource("Animation_gh776"),
@ -311,34 +311,6 @@ tracks/0/keys = {
"values": [Vector3(0, 0, 0), Vector3(0.0349066, 0, 0), Vector3(0, 0, 0)] "values": [Vector3(0, 0, 0), Vector3(0.0349066, 0, 0), Vector3(0, 0, 0)]
} }
[sub_resource type="Animation" id="Animation_vsknp"]
resource_name = "land_right"
length = 1.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera:rotation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-0.0349066, 0, -0.0174533), Vector3(0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Camera:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5, 1.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(0, -0.1, 0), Vector3(0, 0, 0)]
}
[sub_resource type="Animation" id="Animation_l1rph"] [sub_resource type="Animation" id="Animation_l1rph"]
resource_name = "land_left" resource_name = "land_left"
length = 1.5 length = 1.5
@ -367,6 +339,34 @@ tracks/1/keys = {
"values": [Vector3(0, 0, 0), Vector3(0, -0.1, 0), Vector3(0, 0, 0)] "values": [Vector3(0, 0, 0), Vector3(0, -0.1, 0), Vector3(0, 0, 0)]
} }
[sub_resource type="Animation" id="Animation_vsknp"]
resource_name = "land_right"
length = 1.5
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Camera:rotation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-0.0349066, 0, -0.0174533), Vector3(0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("Camera:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.5, 1.5),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(0, -0.1, 0), Vector3(0, 0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_qeg5r"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_qeg5r"]
_data = { _data = {
"RESET": SubResource("Animation_fvvjq"), "RESET": SubResource("Animation_fvvjq"),