From f1c978829872749f458cf061630aa7376b4dc06e Mon Sep 17 00:00:00 2001 From: Zakarya Date: Wed, 24 Jan 2024 16:43:18 -0800 Subject: [PATCH] Add a comment explaining a piece of code and tweak the headbob animation --- addons/fpc/character.gd | 3 +++ addons/fpc/character.tscn | 56 +++++++++++++++++++-------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/addons/fpc/character.gd b/addons/fpc/character.gd index c1b8342..97d4802 100644 --- a/addons/fpc/character.gd +++ b/addons/fpc/character.gd @@ -238,6 +238,9 @@ func headbob_animation(moving): 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. else: HEADBOB_ANIMATION.play("RESET", 0.25) diff --git a/addons/fpc/character.tscn b/addons/fpc/character.tscn index ea1a55a..3747b5c 100644 --- a/addons/fpc/character.tscn +++ b/addons/fpc/character.tscn @@ -14,6 +14,33 @@ material = SubResource("StandardMaterial3D_kp17n") [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_uy03j"] +[sub_resource type="Animation" id="Animation_pqev3"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Mesh:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 1, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Head:position") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 1.5, 0)] +} + [sub_resource type="Animation" id="Animation_5ec5e"] resource_name = "crouch" length = 0.2 @@ -78,33 +105,6 @@ tracks/4/keys = { "values": [Vector3(0, 1.5, 0), Vector3(0, 1.12508, 0)] } -[sub_resource type="Animation" id="Animation_pqev3"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("Mesh:position") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector3(0, 1, 0)] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("Head:position") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector3(0, 1.5, 0)] -} - [sub_resource type="AnimationLibrary" id="AnimationLibrary_5e5t5"] _data = { "RESET": SubResource("Animation_pqev3"), @@ -172,7 +172,7 @@ 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.25, 0, 0.25, 0, -0.05, -0.2, 0.005, 0.2, 0.005, 0, -0.25, 0, 0.25, 0, -0.05, -0.2, 0.005, 0.25, 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"