Implement walking animation

This commit is contained in:
WiseNoodle
2025-08-21 19:55:17 -04:00
parent 7eaae582b2
commit c759004028
5 changed files with 1825 additions and 19 deletions

View File

@@ -23,7 +23,7 @@ properties/3/path = NodePath(".:scale")
properties/3/spawn = true
properties/3/replication_mode = 2
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("camera", "neck", "body", "head")]
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("camera", "neck", "body", "head", "animation_player")]
collision_layer = 2
collision_mask = 3
script = ExtResource("1_ulp21")
@@ -31,6 +31,7 @@ camera = NodePath("Neck/Camera3D")
neck = NodePath("Neck")
body = NodePath("Mesh")
head = NodePath("Neck/HeadBoneAttachment3D/head")
animation_player = NodePath("Mesh/AnimationPlayer")
[node name="Neck" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.297908, 0)
@@ -39,7 +40,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.297908, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.144889, 0)
[node name="HeadBoneAttachment3D" type="BoneAttachment3D" parent="Neck"]
transform = Transform3D(0.999891, -0.0147331, 8.88612e-05, 0.0147334, 0.999884, -0.00387741, -3.17246e-05, 0.0038783, 0.999992, -0.00124739, -0.0512225, 0.0207334)
transform = Transform3D(0.999959, -0.00908396, 8.09411e-05, 0.00908177, 0.999849, 0.0147945, -0.000215322, -0.0147932, 0.99989, -0.0013746, -0.0538376, 0.0128872)
bone_name = "HeadBone.002"
bone_idx = 8
use_external_skeleton = true
@@ -62,24 +63,25 @@ replication_config = SubResource("SceneReplicationConfig_ulp21")
[node name="Mesh" parent="." instance=ExtResource("2_3c3w1")]
[node name="Skeleton3D" parent="Mesh/Armature" index="0"]
bones/0/position = Vector3(0, -0.320764, 0)
bones/0/rotation = Quaternion(0.0267963, 0.000130782, 0.00376776, 0.999634)
bones/0/position = Vector3(4.26202e-05, -0.32356, -0.000609326)
bones/0/rotation = Quaternion(0.0203988, 0.00010767, 0.00391705, 0.999784)
bones/1/rotation = Quaternion(-0.0248584, -6.36843e-12, 9.57895e-11, 0.999691)
bones/2/rotation = Quaternion(0.00281631, -0.0180931, 0.989426, 0.143881)
bones/3/rotation = Quaternion(0.001047, -0.0103569, 0.223692, 0.974604)
bones/4/rotation = Quaternion(-0.0089874, 0.558154, 0.0496036, 0.828204)
bones/5/rotation = Quaternion(-0.0281853, -0.000552969, -0.987355, 0.156)
bones/6/rotation = Quaternion(-0.108633, -0.725783, -0.0876535, 0.673613)
bones/7/rotation = Quaternion(-0.0509695, 0.0872043, 0.0608335, 0.993024)
bones/9/rotation = Quaternion(0.0986331, -0.098018, 0.990245, 0.00888019)
bones/10/rotation = Quaternion(0.314326, 0.12313, -0.0184789, 0.941115)
bones/11/rotation = Quaternion(0.0103559, -0.0500689, 0.998604, 0.0132673)
bones/12/rotation = Quaternion(0.236219, 0.00258908, -0.0020006, 0.971694)
bones/13/position = Vector3(-0.0944914, -0.662892, -0.00320576)
bones/14/position = Vector3(0.0807187, -0.66852, 0.00722197)
bones/2/rotation = Quaternion(0.0914404, 0.0920409, 0.97708, 0.168765)
bones/3/rotation = Quaternion(0.0520362, 2.17449e-05, 0.221285, 0.97382)
bones/4/rotation = Quaternion(0.0161356, 0.000328901, 0.0898733, 0.995822)
bones/5/rotation = Quaternion(-0.112112, 0.113354, -0.962453, 0.219697)
bones/6/rotation = Quaternion(-0.0678804, 0.0011636, -0.221119, 0.972881)
bones/7/rotation = Quaternion(-0.0215328, 0.000574495, -0.0928375, 0.995448)
bones/8/rotation = Quaternion(-0.00293645, 7.25297e-05, 0.000623416, 0.999996)
bones/9/rotation = Quaternion(0.0803629, -0.105083, 0.98951, -0.0580557)
bones/10/rotation = Quaternion(0.00201719, 0.0658942, -8.48654e-05, 0.997825)
bones/11/rotation = Quaternion(0.987418, -0.00859132, 0.00926525, 0.157626)
bones/12/rotation = Quaternion(0.193335, -0.014129, -7.2887e-05, 0.981031)
bones/13/position = Vector3(-0.0477975, -0.700956, -0.0941017)
bones/14/position = Vector3(0.0828021, -0.67129, 0.039274)
bones/14/rotation = Quaternion(-0.00153534, -0.704023, 0.70978, -0.023698)
bones/15/position = Vector3(-0.166587, -0.218294, 0.00449948)
bones/16/position = Vector3(0.208654, -0.217145, 0.00461988)
bones/15/position = Vector3(-0.169587, -0.207477, 0.0975888)
bones/16/position = Vector3(0.202683, -0.196121, -0.0935159)
[node name="AnimationPlayer" parent="Mesh" index="1"]
autoplay = "Idle"

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -24,6 +24,7 @@ class_name Player extends CharacterBody3D
@export var body: Node3D
@export var head: Node3D
@export var watch_face: MeshInstance3D
@export var animation_player: AnimationPlayer
var jumping: bool = false
@@ -42,7 +43,7 @@ func _ready():
print("-> [%s] Authority granted. Setting up camera and input." % name)
camera.make_current()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
$Mesh.hide()
#$Mesh.hide() # commented out; we want self-body view
$Label3D.hide()
head.hide()
@@ -107,6 +108,10 @@ func walk(delta: float) -> Vector3:
var _forward: Vector3 = neck.global_transform.basis * Vector3(move_dir.x, 0, move_dir.y)
var walk_dir: Vector3 = Vector3(_forward.x, 0, _forward.z).normalized()
walk_vel = walk_vel.move_toward(walk_dir * speed * move_dir.length(), acceleration * delta)
if walk_vel:
animation_player.play("Walk")
else:
animation_player.play("Idle")
return walk_vel