From b815a6603c3a21cb5132eaf5d051c30423a4c994 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 3 Feb 2024 00:57:33 +0100 Subject: [PATCH] Added animations --- client/Main.tscn | 2 +- client/player/Animation.gd | 9 ++++++++- client/player/Player.tscn | 30 +++++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/client/Main.tscn b/client/Main.tscn index ea40372..27e28ed 100644 --- a/client/Main.tscn +++ b/client/Main.tscn @@ -91,7 +91,7 @@ autostart = true [node name="CameraPivot" type="Node3D" parent="World"] [node name="Camera" type="Camera3D" parent="World/CameraPivot" node_paths=PackedStringArray("center")] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 10, 10) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 15, 15) current = true fov = 30.0 size = 10.0 diff --git a/client/player/Animation.gd b/client/player/Animation.gd index 006132e..9bed280 100644 --- a/client/player/Animation.gd +++ b/client/player/Animation.gd @@ -1,16 +1,23 @@ extends Node +@export var character: Character @export var animation_player: AnimationPlayer @export var blend_time: float var next_animation: StringName = "RESET" func _ready(): + assert(character) assert(animation_player) assert(blend_time >= 0.0) func _process(_delta): - play("idle") + if character.velocity.y > 0: + play("female/jump") + elif character.direction != Vector3.ZERO: + play("female/run") + else: + play("female/idle") if animation_player.current_animation == next_animation: return diff --git a/client/player/Player.tscn b/client/player/Player.tscn index 0d67db2..a4c8880 100644 --- a/client/player/Player.tscn +++ b/client/player/Player.tscn @@ -1,14 +1,25 @@ -[gd_scene load_steps=6 format=3 uid="uid://2lcnu3dy54lx"] +[gd_scene load_steps=11 format=3 uid="uid://2lcnu3dy54lx"] [ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"] [ext_resource type="PackedScene" uid="uid://dnr3o1rbkqpgu" path="res://assets/models/female/Female.blend" id="2_8nah6"] [ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/health/HealthComponent.tscn" id="2_np5ag"] [ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/ui/font/ubuntu_nf_regular.ttf" id="4_76ehj"] +[ext_resource type="Script" path="res://player/Animation.gd" id="5_d4uw4"] +[ext_resource type="Animation" uid="uid://dtjukkf6gxotr" path="res://assets/animations/idle.res" id="6_af1ii"] +[ext_resource type="Animation" uid="uid://cdff3pqukhf3q" path="res://assets/animations/run.res" id="7_23e77"] +[ext_resource type="Animation" uid="uid://dgcitda225sht" path="res://assets/animations/jump.res" id="8_v1exn"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"] radius = 0.25 height = 1.6 +[sub_resource type="AnimationLibrary" id="AnimationLibrary_umd50"] +_data = { +"idle": ExtResource("6_af1ii"), +"jump": ExtResource("8_v1exn"), +"run": ExtResource("7_23e77") +} + [node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("model") groups=["player"]] script = ExtResource("1_8gebs") model = NodePath("Model") @@ -21,10 +32,23 @@ model = NodePath("Model") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0) shape = SubResource("CapsuleShape3D_2f50n") -[node name="Health" parent="." instance=ExtResource("2_np5ag")] - [node name="Label" type="Label3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 0) billboard = 1 text = "Player" font = ExtResource("4_76ehj") + +[node name="Animation" type="Node" parent="." node_paths=PackedStringArray("character", "animation_player")] +script = ExtResource("5_d4uw4") +character = NodePath("..") +animation_player = NodePath("../AnimationPlayer") +blend_time = 0.2 + +[node name="Health" parent="." instance=ExtResource("2_np5ag")] + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +root_node = NodePath("../Model/Female") +libraries = { +"female": SubResource("AnimationLibrary_umd50") +} +playback_default_blend_time = 0.2