add AnimationTrees and state machines
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://k11usj2shbtr"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://k11usj2shbtr"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_1u65s"]
|
||||
[ext_resource type="Script" path="res://scripts/units/ant_nitwit.gd" id="2_f1bdv"]
|
||||
@@ -8,6 +8,27 @@
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0iwx2"]
|
||||
albedo_color = Color(0.344076, 0.344076, 0.344076, 1)
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_foq4x"]
|
||||
animation = &"idle"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_lxe13"]
|
||||
animation = &"walk"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace1D" id="AnimationNodeBlendSpace1D_rro5b"]
|
||||
blend_point_0/node = SubResource("AnimationNodeAnimation_foq4x")
|
||||
blend_point_0/pos = 0.0
|
||||
blend_point_1/node = SubResource("AnimationNodeAnimation_lxe13")
|
||||
blend_point_1/pos = 1.0
|
||||
min_space = 0.0
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_j3gya"]
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_2257g"]
|
||||
states/locomotion/node = SubResource("AnimationNodeBlendSpace1D_rro5b")
|
||||
states/locomotion/position = Vector2(346, 100)
|
||||
transitions = ["Start", "locomotion", SubResource("AnimationNodeStateMachineTransition_j3gya")]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_e8dcp"]
|
||||
radius = 0.25
|
||||
|
||||
@@ -21,23 +42,28 @@ surface_material_override/0 = SubResource("StandardMaterial3D_0iwx2")
|
||||
[node name="AnimationPlayer" parent="." index="1"]
|
||||
deterministic = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="2"]
|
||||
[node name="AnimationTree" type="AnimationTree" parent="." index="2"]
|
||||
tree_root = SubResource("AnimationNodeStateMachine_2257g")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/locomotion/blend_position = 0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="3"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
|
||||
shape = SubResource("SphereShape3D_e8dcp")
|
||||
|
||||
[node name="SelectionSprite" type="Sprite3D" parent="." index="3"]
|
||||
[node name="SelectionSprite" type="Sprite3D" parent="." index="4"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||
pixel_size = 0.0055
|
||||
axis = 1
|
||||
texture = ExtResource("3_hxm2m")
|
||||
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="4"]
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="5"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||
pixel_size = 0.0085
|
||||
axis = 1
|
||||
texture = ExtResource("4_vrkmw")
|
||||
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="5"]
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="6"]
|
||||
path_desired_distance = 0.5
|
||||
target_desired_distance = 0.5
|
||||
path_height_offset = 0.5
|
||||
@@ -46,5 +72,5 @@ height = 0.5
|
||||
radius = 0.25
|
||||
neighbor_distance = 10.0
|
||||
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="6"]
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="7"]
|
||||
aabb = AABB(-0.5, 0, -0.5, 1, 0.5, 1)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://d4c6ujs1ra1ob"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://d4c6ujs1ra1ob"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_0xhpn"]
|
||||
[ext_resource type="Script" path="res://scripts/units/aphid.gd" id="2_mwxoc"]
|
||||
@@ -7,6 +7,28 @@
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_0qv88"]
|
||||
albedo_color = Color(0.297709, 0.675387, 0.346609, 1)
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_v2qr3"]
|
||||
animation = &"idle"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_1hsi0"]
|
||||
animation = &"walk"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace1D" id="AnimationNodeBlendSpace1D_xy8wv"]
|
||||
blend_point_0/node = SubResource("AnimationNodeAnimation_v2qr3")
|
||||
blend_point_0/pos = 0.0
|
||||
blend_point_1/node = SubResource("AnimationNodeAnimation_1hsi0")
|
||||
blend_point_1/pos = 1.0
|
||||
min_space = 0.0
|
||||
sync = true
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_hnsr3"]
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_avnq4"]
|
||||
states/locomotion/node = SubResource("AnimationNodeBlendSpace1D_xy8wv")
|
||||
states/locomotion/position = Vector2(365, 100)
|
||||
transitions = ["Start", "locomotion", SubResource("AnimationNodeStateMachineTransition_hnsr3")]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_e8dcp"]
|
||||
radius = 0.25
|
||||
|
||||
@@ -20,17 +42,22 @@ surface_material_override/0 = SubResource("StandardMaterial3D_0qv88")
|
||||
[node name="AnimationPlayer" parent="." index="1"]
|
||||
deterministic = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="2"]
|
||||
[node name="AnimationTree" type="AnimationTree" parent="." index="2"]
|
||||
tree_root = SubResource("AnimationNodeStateMachine_avnq4")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/locomotion/blend_position = 0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="3"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
|
||||
shape = SubResource("SphereShape3D_e8dcp")
|
||||
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="3"]
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="4"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||
pixel_size = 0.0085
|
||||
axis = 1
|
||||
texture = ExtResource("4_w3eta")
|
||||
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="4"]
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="5"]
|
||||
path_desired_distance = 0.5
|
||||
target_desired_distance = 0.5
|
||||
path_height_offset = 0.5
|
||||
@@ -39,5 +66,5 @@ height = 0.5
|
||||
radius = 0.25
|
||||
neighbor_distance = 10.0
|
||||
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="5"]
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="6"]
|
||||
aabb = AABB(-0.5, 0, -0.5, 1, 0.5, 1)
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://cfixshlmwhpmi"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://cfixshlmwhpmi"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bi231xk2sp410" path="res://assets/models/ant.glb" id="1_ff64u"]
|
||||
[ext_resource type="Texture2D" uid="uid://dehqm00kiljut" path="res://assets/textures/selection_unit_decal.png" id="2_5725f"]
|
||||
[ext_resource type="Script" path="res://scripts/units/controlled_unit.gd" id="2_gj6f7"]
|
||||
[ext_resource type="Texture2D" uid="uid://duf132faskeid" path="res://assets/textures/selection_unit_hover_decal.png" id="4_umx1w"]
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_s05ju"]
|
||||
animation = &"idle"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimationNodeAnimation_5dqro"]
|
||||
animation = &"walk"
|
||||
|
||||
[sub_resource type="AnimationNodeBlendSpace1D" id="AnimationNodeBlendSpace1D_tclyw"]
|
||||
blend_point_0/node = SubResource("AnimationNodeAnimation_s05ju")
|
||||
blend_point_0/pos = 0.0
|
||||
blend_point_1/node = SubResource("AnimationNodeAnimation_5dqro")
|
||||
blend_point_1/pos = 1.0
|
||||
min_space = 0.0
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_o3fey"]
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_3rpsy"]
|
||||
states/locomotion/node = SubResource("AnimationNodeBlendSpace1D_tclyw")
|
||||
states/locomotion/position = Vector2(351, 100)
|
||||
transitions = ["Start", "locomotion", SubResource("AnimationNodeStateMachineTransition_o3fey")]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_e8dcp"]
|
||||
radius = 0.25
|
||||
|
||||
@@ -15,23 +36,28 @@ script = ExtResource("2_gj6f7")
|
||||
[node name="AnimationPlayer" parent="." index="1"]
|
||||
deterministic = true
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="2"]
|
||||
[node name="AnimationTree" type="AnimationTree" parent="." index="2"]
|
||||
tree_root = SubResource("AnimationNodeStateMachine_3rpsy")
|
||||
anim_player = NodePath("../AnimationPlayer")
|
||||
parameters/locomotion/blend_position = 0
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="." index="3"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.25, 0)
|
||||
shape = SubResource("SphereShape3D_e8dcp")
|
||||
|
||||
[node name="SelectionSprite" type="Sprite3D" parent="." index="3"]
|
||||
[node name="SelectionSprite" type="Sprite3D" parent="." index="4"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||
pixel_size = 0.0055
|
||||
axis = 1
|
||||
texture = ExtResource("2_5725f")
|
||||
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="4"]
|
||||
[node name="HoverSprite" type="Sprite3D" parent="." index="5"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0021804, 0.00953716, -0.00236732)
|
||||
pixel_size = 0.0085
|
||||
axis = 1
|
||||
texture = ExtResource("4_umx1w")
|
||||
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="5"]
|
||||
[node name="NavigationAgent3D" type="NavigationAgent3D" parent="." index="6"]
|
||||
path_desired_distance = 0.5
|
||||
target_desired_distance = 0.5
|
||||
path_height_offset = 0.5
|
||||
@@ -40,5 +66,5 @@ height = 0.5
|
||||
radius = 0.25
|
||||
neighbor_distance = 10.0
|
||||
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="6"]
|
||||
[node name="VisibleOnScreenNotifier3D" type="VisibleOnScreenNotifier3D" parent="." index="7"]
|
||||
aabb = AABB(-0.5, 0, -0.5, 1, 0.5, 1)
|
||||
|
||||
@@ -14,7 +14,7 @@ var wandering_timer: float = 0
|
||||
|
||||
@onready var hover_sprite: Sprite3D = $HoverSprite
|
||||
@onready var nav_agent: NavigationAgent3D = $NavigationAgent3D
|
||||
@onready var animation_player: AnimationPlayer = $AnimationPlayer
|
||||
@onready var animation_tree: AnimationTree = $AnimationTree
|
||||
@onready var visibility_notifier: VisibleOnScreenNotifier3D = (
|
||||
$VisibleOnScreenNotifier3D
|
||||
)
|
||||
@@ -24,7 +24,7 @@ var wandering_timer: float = 0
|
||||
func _ready() -> void:
|
||||
assert(hover_sprite != null, "hover_sprite missing!")
|
||||
assert(nav_agent != null, "nav_agent missing!")
|
||||
assert(animation_player != null, "animation_player missing!")
|
||||
assert(animation_tree != null, "animation_tree missing!")
|
||||
assert(visibility_notifier != null, "visibility_notifier missing!")
|
||||
|
||||
set_hovered(false)
|
||||
@@ -74,7 +74,7 @@ func _animate(delta: float) -> void:
|
||||
) + PI
|
||||
return
|
||||
|
||||
if velocity.length() > 0.1:
|
||||
if velocity.length() > 0.01:
|
||||
var velocity_normalized := velocity.normalized()
|
||||
var angle := atan2(-velocity_normalized.x, -velocity_normalized.z) + PI
|
||||
global_rotation.y = rotate_toward(
|
||||
@@ -83,9 +83,11 @@ func _animate(delta: float) -> void:
|
||||
TURN_SPEED * delta,
|
||||
)
|
||||
# look_at(global_position + velocity, Vector3.UP, true)
|
||||
animation_player.play('walk')
|
||||
else:
|
||||
animation_player.play('idle')
|
||||
|
||||
animation_tree.set(
|
||||
"parameters/locomotion/blend_position",
|
||||
velocity.length() / MOVE_SPEED,
|
||||
)
|
||||
|
||||
hover_sprite.visible = hovered
|
||||
|
||||
|
||||
Reference in New Issue
Block a user