Animation refresh

This commit is contained in:
2024-02-29 19:36:50 -08:00
parent f1c9788298
commit 3b78a2fcf8
2 changed files with 109 additions and 14 deletions

View File

@ -112,7 +112,11 @@ func _physics_process(delta):
if jump_animation: if jump_animation:
if !was_on_floor and is_on_floor(): # Just landed if !was_on_floor and is_on_floor(): # Just landed
JUMP_ANIMATION.play("land") match randi() % 2:
0:
JUMP_ANIMATION.play("land_left")
1:
JUMP_ANIMATION.play("land_right")
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
@ -231,16 +235,25 @@ func update_camera_fov():
func headbob_animation(moving): func headbob_animation(moving):
if moving and is_on_floor(): if moving and is_on_floor():
var use_headbob_animation : String
match state:
"normal","crouching":
use_headbob_animation = "walk"
"sprinting":
use_headbob_animation = "sprint"
var was_playing : bool = false var was_playing : bool = false
if HEADBOB_ANIMATION.current_animation == "headbob": if HEADBOB_ANIMATION.current_animation == use_headbob_animation:
was_playing = true was_playing = true
HEADBOB_ANIMATION.play("headbob", 0.25)
HEADBOB_ANIMATION.play(use_headbob_animation, 0.25)
HEADBOB_ANIMATION.speed_scale = (current_speed / base_speed) * 1.75 HEADBOB_ANIMATION.speed_scale = (current_speed / base_speed) * 1.75
if !was_playing: if !was_playing:
HEADBOB_ANIMATION.seek(float(randi() % 2)) # Randomize the initial headbob direction 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. # 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. # 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. # randi() % 2 returns either 0 or 1, and so the animation randomly starts at one of the starting positions.
# This code is extremely performant but it makes no sense.
else: else:
HEADBOB_ANIMATION.play("RESET", 0.25) HEADBOB_ANIMATION.play("RESET", 0.25)

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://cc1m2a1obsyn4"] [gd_scene load_steps=21 format=3 uid="uid://cc1m2a1obsyn4"]
[ext_resource type="Script" path="res://addons/fpc/character.gd" id="1_0t4e8"] [ext_resource type="Script" path="res://addons/fpc/character.gd" id="1_0t4e8"]
[ext_resource type="PackedScene" uid="uid://3mij3cjhkwsm" path="res://addons/fpc/reticles/reticle_1.tscn" id="2_uuexm"] [ext_resource type="PackedScene" uid="uid://3mij3cjhkwsm" path="res://addons/fpc/reticles/reticle_1.tscn" id="2_uuexm"]
@ -150,7 +150,7 @@ tracks/2/keys = {
} }
[sub_resource type="Animation" id="Animation_lrqmv"] [sub_resource type="Animation" id="Animation_lrqmv"]
resource_name = "headbob" resource_name = "walk"
length = 2.0 length = 2.0
loop_mode = 1 loop_mode = 1
tracks/0/type = "bezier" tracks/0/type = "bezier"
@ -160,8 +160,8 @@ tracks/0/path = NodePath("Camera:position:x")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"handle_modes": PackedInt32Array(0, 0, 0, 0, 0), "handle_modes": PackedInt32Array(0, 1, 0, 1, 0),
"points": PackedFloat32Array(0.04, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, -0.04, -0.25, 0, 0.25, 0, 0, -0.25, 0, 0.25, 0, 0.04, -0.25, 0, 0.25, 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) "times": PackedFloat32Array(0, 0.5, 1, 1.5, 2)
} }
tracks/1/type = "bezier" tracks/1/type = "bezier"
@ -187,10 +187,49 @@ 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_8ku67"]
resource_name = "sprint"
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.06, -0.25, 0, 0.25, -0.01, 0, 0, 0, 0, 0, -0.06, -0.25, 0.01, 0.25, 0.01, 0, 0, 0, 0, 0, 0.06, -0.25, -0.01, 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.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="AnimationLibrary" id="AnimationLibrary_o0unb"] [sub_resource type="AnimationLibrary" id="AnimationLibrary_o0unb"]
_data = { _data = {
"RESET": SubResource("Animation_gh776"), "RESET": SubResource("Animation_gh776"),
"headbob": SubResource("Animation_lrqmv") "sprint": SubResource("Animation_8ku67"),
"walk": SubResource("Animation_lrqmv")
} }
[sub_resource type="Animation" id="Animation_fvvjq"] [sub_resource type="Animation" id="Animation_fvvjq"]
@ -210,6 +249,7 @@ tracks/0/keys = {
[sub_resource type="Animation" id="Animation_s07ye"] [sub_resource type="Animation" id="Animation_s07ye"]
resource_name = "jump" resource_name = "jump"
length = 3.0
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
@ -217,14 +257,15 @@ tracks/0/path = NodePath("Camera:rotation")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1), "times": PackedFloat32Array(0, 0.6, 3),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1),
"update": 0, "update": 0,
"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"] [sub_resource type="Animation" id="Animation_vsknp"]
resource_name = "land" resource_name = "land_right"
length = 1.5
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/imported = false tracks/0/imported = false
tracks/0/enabled = true tracks/0/enabled = true
@ -232,17 +273,58 @@ tracks/0/path = NodePath("Camera:rotation")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5, 1), "times": PackedFloat32Array(0, 0.5, 1.5),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1),
"update": 0, "update": 0,
"values": [Vector3(0, 0, 0), Vector3(-0.0349066, 0, 0), Vector3(0, 0, 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"]
resource_name = "land_left"
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"),
"jump": SubResource("Animation_s07ye"), "jump": SubResource("Animation_s07ye"),
"land": SubResource("Animation_vsknp") "land_left": SubResource("Animation_l1rph"),
"land_right": SubResource("Animation_vsknp")
} }
[sub_resource type="Theme" id="Theme_wdf0f"] [sub_resource type="Theme" id="Theme_wdf0f"]
@ -287,7 +369,7 @@ transform = Transform3D(1, 0, 0, 0, 0.999391, -0.0348995, 0, 0.0348995, 0.999391
libraries = { libraries = {
"": SubResource("AnimationLibrary_o0unb") "": SubResource("AnimationLibrary_o0unb")
} }
blend_times = [&"RESET", &"RESET", 0.5, &"RESET", &"headbob", 0.5, &"headbob", &"RESET", 0.5] blend_times = [&"RESET", &"RESET", 0.5, &"RESET", &"walk", 0.5, &"walk", &"RESET", 0.5]
[node name="JumpAnimation" type="AnimationPlayer" parent="Head"] [node name="JumpAnimation" type="AnimationPlayer" parent="Head"]
libraries = { libraries = {