Added basic animations for player.

main
Martin Felis 2024-09-08 16:57:39 +02:00
parent 4ea895ed30
commit f280271de5
7 changed files with 57837 additions and 66 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,62 +1,80 @@
[gd_scene load_steps=2 format=3 uid="uid://dy8vjf760prhq"] [gd_scene load_steps=15 format=3 uid="uid://dy8vjf760prhq"]
[ext_resource type="PackedScene" uid="uid://c0ot1kp5fekqy" path="res://assets/3rdparty/KayKit_Adventurers_1.0_EXTRA/Characters/gltf/Rogue.glb" id="1_ps6bc"] [ext_resource type="PackedScene" uid="uid://c0ot1kp5fekqy" path="res://assets/3rdparty/KayKit_Adventurers_1.0_EXTRA/Characters/gltf/Rogue.glb" id="1_rsxsi"]
[ext_resource type="AnimationLibrary" uid="uid://dbaynxuqbkor6" path="res://assets/characters/rogue_animation_library.tres" id="2_18sv4"]
[node name="Rogue" instance=ExtResource("1_ps6bc")] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_fe868"]
animation = &"rogue/1H_Melee_Attack_Chop"
[node name="Skeleton3D" parent="Rig" index="0"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_dqt6d"]
bones/1/position = Vector3(0, 0.392064, 0) animation = &"rogue/Idle"
bones/1/rotation = Quaternion(-1.11123e-10, 0.0431578, 2.57241e-09, 0.999068)
bones/4/rotation = Quaternion(-0.559906, -0.0608803, -0.643974, 0.517779)
bones/5/rotation = Quaternion(3.65498e-08, -4.88301e-08, -0.494719, 0.869053)
bones/7/rotation = Quaternion(-0.321065, -0.325319, 0.145726, 0.87741)
bones/8/rotation = Quaternion(-3.6586e-09, 6.87811e-09, -0.707107, 0.707107)
bones/10/rotation = Quaternion(-0.618244, 0.0807287, 0.618012, 0.478873)
bones/11/rotation = Quaternion(2.09853e-08, 5.12855e-08, 0.517939, 0.855417)
bones/13/rotation = Quaternion(-0.319291, 0.300524, -0.22735, 0.869512)
bones/14/rotation = Quaternion(-1.02444e-09, -4.24391e-09, 0.707107, 0.707107)
bones/19/rotation = Quaternion(-5.8061e-11, -0.0313416, -1.88013e-09, 0.999509)
bones/21/rotation = Quaternion(0.993715, 0.0837146, 0.0735038, 0.0109185)
bones/22/rotation = Quaternion(0.195602, 6.26228e-08, -1.32239e-07, 0.980683)
bones/23/rotation = Quaternion(-0.517564, -0.209497, 0.0436549, 0.828452)
bones/25/rotation = Quaternion(0.997322, -0.0294574, 0.0315293, 0.0590483)
bones/26/rotation = Quaternion(0.274008, -6.38135e-08, 1.92761e-07, 0.961727)
bones/27/rotation = Quaternion(-0.559039, 0.114513, -0.00862763, 0.82115)
bones/28/rotation = Quaternion(3.04797e-08, 0.920355, -0.391084, -6.94849e-08)
bones/29/rotation = Quaternion(0.707107, -2.29302e-07, -4.60551e-08, 0.707107)
bones/30/position = Vector3(0.202182, 0.0259903, 0.205181)
bones/30/rotation = Quaternion(-0.707107, -7.05285e-08, -7.05285e-08, 0.707107)
bones/31/rotation = Quaternion(9.65792e-09, 1.77955e-09, 0.985719, -0.168398)
bones/32/rotation = Quaternion(-1.04035e-07, 0.391084, 0.920355, -2.9526e-08)
bones/34/rotation = Quaternion(1, -3.10863e-15, 1.94707e-07, -6.91739e-22)
bones/36/rotation = Quaternion(0.707107, -3.82385e-08, 1.45009e-07, 0.707107)
bones/37/rotation = Quaternion(-0.707107, -7.05285e-08, -7.05285e-08, 0.707107)
bones/38/rotation = Quaternion(-5.83589e-09, 6.43837e-10, 0.994809, 0.101756)
bones/39/rotation = Quaternion(-1.04035e-07, 0.391084, 0.920355, -2.95261e-08)
bones/44/position = Vector3(0.520841, 0.788312, -0.0576373)
bones/44/rotation = Quaternion(0.794627, -1.11759e-07, 0.607098, -5.96046e-08)
bones/46/position = Vector3(-0.510844, 0.788312, 0.0597369)
bones/46/rotation = Quaternion(-0.758253, -1.52737e-07, 0.651961, -1.11759e-08)
[node name="Knife_Offhand" parent="Rig/Skeleton3D" index="0"] [sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_g5g2g"]
transform = Transform3D(9.17323e-08, 0.262865, 0.964832, 0.999999, -5.48367e-07, 4.74853e-07, 8.68286e-07, 0.964832, -0.262865, 0.507764, 0.636705, -0.0185365) animation = &"rogue/Running_A"
visible = false
[node name="1H_Crossbow" parent="Rig/Skeleton3D" index="1"] [sub_resource type="AnimationNodeTimeScale" id="AnimationNodeTimeScale_7v7om"]
transform = Transform3D(0.988701, -0.149894, -4.17134e-07, -8.6882e-07, -1.08398e-06, -0.999999, 0.149894, 0.988702, -1.49706e-06, -0.489506, 0.745658, 0.096339)
visible = false
[node name="2H_Crossbow" parent="Rig/Skeleton3D" index="2"] [sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_uc6vu"]
transform = Transform3D(0.988701, -0.149894, -4.17134e-07, -8.6882e-07, -1.08398e-06, -0.999999, 0.149894, 0.988702, -1.49706e-06, -0.489506, 0.745658, 0.096339) nodes/Animation/node = SubResource("AnimationNodeAnimation_g5g2g")
visible = false nodes/Animation/position = Vector2(40, 180)
nodes/TimeScale/node = SubResource("AnimationNodeTimeScale_7v7om")
nodes/TimeScale/position = Vector2(340, 180)
nodes/output/position = Vector2(640, 160)
node_connections = [&"TimeScale", 0, &"Animation", &"output", 0, &"TimeScale"]
[node name="Knife" parent="Rig/Skeleton3D" index="3"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ryaua"]
transform = Transform3D(4.21314e-07, -0.149893, 0.988701, 0.999999, -9.35798e-07, -8.50581e-07, 1.34781e-06, 0.988702, 0.149894, -0.491058, 0.64103, 0.10658) advance_mode = 2
visible = false
[node name="Throwable" parent="Rig/Skeleton3D" index="4"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_1dwt2"]
transform = Transform3D(4.37053e-07, -0.149894, 0.988701, 0.999999, -9.21064e-07, -8.64267e-07, 1.3353e-06, 0.988702, 0.149894, -0.518076, 0.64103, 0.28479) advance_mode = 2
visible = false advance_condition = &"attack"
[node name="Rogue_Cape" parent="Rig/Skeleton3D" index="5"] [sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_w1i70"]
transform = Transform3D(0.996275, -5.14962e-09, 0.0862354, 5.13044e-09, 1, 4.44078e-10, -0.0862354, 1.47756e-15, 0.996275, -4.17227e-09, 1.20227, 1.19714e-15) switch_mode = 2
advance_mode = 2
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_chmuj"]
xfade_time = 0.1
advance_mode = 2
advance_condition = &"running"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_oa1w1"]
xfade_time = 0.1
advance_mode = 2
advance_condition = &"idle"
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_2nd5h"]
xfade_time = 0.2
advance_mode = 2
advance_condition = &"running"
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_h0y4b"]
states/End/position = Vector2(902, 102)
states/Start/position = Vector2(189, 123)
states/rogue_1H_Melee_Attack_Chop/node = SubResource("AnimationNodeAnimation_fe868")
states/rogue_1H_Melee_Attack_Chop/position = Vector2(677, 123)
states/rogue_Idle/node = SubResource("AnimationNodeAnimation_dqt6d")
states/rogue_Idle/position = Vector2(422, 123)
states/running/node = SubResource("AnimationNodeBlendTree_uc6vu")
states/running/position = Vector2(422, 285)
transitions = ["Start", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_ryaua"), "rogue_Idle", "rogue_1H_Melee_Attack_Chop", SubResource("AnimationNodeStateMachineTransition_1dwt2"), "rogue_1H_Melee_Attack_Chop", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_w1i70"), "rogue_Idle", "running", SubResource("AnimationNodeStateMachineTransition_chmuj"), "running", "rogue_Idle", SubResource("AnimationNodeStateMachineTransition_oa1w1"), "rogue_1H_Melee_Attack_Chop", "running", SubResource("AnimationNodeStateMachineTransition_2nd5h")]
graph_offset = Vector2(-12, -72)
[node name="Rogue" type="Node3D"]
[node name="Rogue" parent="." instance=ExtResource("1_rsxsi")]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
root_node = NodePath("../Rogue")
libraries = {
"rogue": ExtResource("2_18sv4")
}
[node name="AnimationTree" type="AnimationTree" parent="."]
root_node = NodePath("../Rogue")
tree_root = SubResource("AnimationNodeStateMachine_h0y4b")
anim_player = NodePath("../AnimationPlayer")
parameters/conditions/attack = false
parameters/conditions/idle = false
parameters/conditions/running = false
parameters/running/TimeScale/scale = 1.5

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,29 @@
class_name Player class_name Player
extends CharacterBody3D extends CharacterBody3D
const SPEED = 5.0 const SPEED = 4.0
const JUMP_VELOCITY = 2.5 const JUMP_VELOCITY = 2.5
@onready var geometry = %Geometry @onready var geometry:Node3D = %Geometry
@onready var actionable_detector = %ActionableDetector @onready var actionable_detector = %ActionableDetector
@onready var animation_tree:AnimationTree = $Geometry/Rogue/AnimationTree
# Get the gravity from the project settings to be synced with RigidBody nodes. # Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity") var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
var inventory:Inventory = Inventory.new() var inventory:Inventory = Inventory.new()
var last_nonzero_velocity:Vector3 = Vector3.BACK var look_direction:Vector3 = Vector3.BACK
signal trigger_message(message:String) signal trigger_message(message:String)
var interaction_state:bool = false
func _process(_delta):
animation_tree.set("parameters/conditions/attack", interaction_state)
if interaction_state:
interaction_state = false
func _physics_process(delta): func _physics_process(delta):
# Add the gravity. # Add the gravity.
if not is_on_floor(): if not is_on_floor():
@ -34,11 +43,17 @@ func _physics_process(delta):
move_and_slide() move_and_slide()
var ground_velocity:Vector2 = Vector2(velocity.x, velocity.z) var ground_velocity:Vector2 = Vector2(velocity.x, velocity.z)
if ground_velocity.length_squared() > 0.1 * 0.1:
last_nonzero_velocity = Vector3(ground_velocity.x, 0, ground_velocity.y).normalized()
geometry.look_at(position - last_nonzero_velocity, Vector3.UP) var is_moving:bool = ground_velocity.length_squared() > 0.1 * 0.1
if is_moving:
look_direction = Vector3(ground_velocity.x, 0, ground_velocity.y).normalized()
elif direction.length_squared() > 0.1 * 0.1:
look_direction = direction
animation_tree.set("parameters/conditions/running", is_moving)
animation_tree.set("parameters/conditions/idle", not is_moving)
geometry.look_at(position - look_direction, Vector3.UP)
func on_item_picked_up(item:Item): func on_item_picked_up(item:Item):
@ -50,4 +65,17 @@ func _unhandled_input(_event: InputEvent) -> void:
if Input.is_action_just_pressed("ui_accept"): if Input.is_action_just_pressed("ui_accept"):
var actionables = actionable_detector.get_overlapping_areas() var actionables = actionable_detector.get_overlapping_areas()
if actionables.size() > 0: if actionables.size() > 0:
print("player position: " + str(position) + " actionables position: " + str(actionables[0].global_position))
look_direction = (actionables[0].global_position - position).normalized()
# geometry.look_at(actionables[0].global_position, Vector3.UP)
actionables[0].action() actionables[0].action()
get_viewport().set_input_as_handled()
return
if Input.is_action_just_pressed("interaction"):
interaction_state = true
get_viewport().set_input_as_handled()
return

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=7 format=3 uid="uid://ch0s3dxx3rpir"] [gd_scene load_steps=7 format=3 uid="uid://ch0s3dxx3rpir"]
[ext_resource type="Script" path="res://objects/player.gd" id="1_sen68"] [ext_resource type="Script" path="res://objects/player.gd" id="1_qkf7c"]
[ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="2_whuis"] [ext_resource type="PackedScene" uid="uid://dy8vjf760prhq" path="res://assets/characters/rogue.tscn" id="2_whuis"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jd31k"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jd31k"]
@ -19,7 +19,7 @@ height = 0.952333
radius = 0.194932 radius = 0.194932
[node name="Player" type="CharacterBody3D"] [node name="Player" type="CharacterBody3D"]
script = ExtResource("1_sen68") script = ExtResource("1_qkf7c")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."] [node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.3, 0)
@ -36,13 +36,13 @@ transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0, 0)
[node name="Rogue" parent="Geometry" instance=ExtResource("2_whuis")] [node name="Rogue" parent="Geometry" instance=ExtResource("2_whuis")]
[node name="ActionableDetector" type="Area3D" parent="."] [node name="ActionableDetector" type="Area3D" parent="Geometry"]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.325311) transform = Transform3D(2.5, 0, 0, 0, 2.5, 0, 0, 0, 2.5, 0, 0, 0.813277)
collision_layer = 0 collision_layer = 0
collision_mask = 16 collision_mask = 16
[node name="CollisionShape3D" type="CollisionShape3D" parent="ActionableDetector"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Geometry/ActionableDetector"]
shape = SubResource("SphereShape3D_wrkyq") shape = SubResource("SphereShape3D_wrkyq")
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]

View File

@ -121,6 +121,13 @@ toggle_inventory={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
] ]
} }
interaction={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
[internationalization] [internationalization]

View File

@ -185,6 +185,7 @@ grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
size_flags_vertical = 3 size_flags_vertical = 3
mouse_filter = 1
theme = ExtResource("4_el4q2") theme = ExtResource("4_el4q2")
script = ExtResource("5_jkbjp") script = ExtResource("5_jkbjp")