Animation tree fixes
This commit is contained in:
@@ -52,6 +52,7 @@ public partial class DataViewer : Control
|
||||
Camera3D.Position = Camera3D.Position.Clamp(new Vector3(0, 0, 1), new Vector3(0, 0, 4));
|
||||
ModelPivot.Rotation = ModelPivot.Rotation.Clamp(Mathf.DegToRad(-60), Mathf.DegToRad(60));
|
||||
_currentModel.SetCurrentDirection(_currentModel.GlobalBasis, -CameraPivot.Basis.Z);
|
||||
Description.Text = (-CameraPivot.RotationDegrees).ToString();
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.Attack))
|
||||
_currentModel.PlayPrimaryAttackAnimation();
|
||||
|
||||
@@ -78,6 +78,7 @@ layout_mode = 2
|
||||
stretch = true
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="CenterContainer/VBoxContainer/HBoxContainer/SubViewportContainer"]
|
||||
own_world_3d = true
|
||||
handle_input_locally = false
|
||||
size = Vector2i(500, 500)
|
||||
render_target_update_mode = 4
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://c16i1gmg6yu5a"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c16i1gmg6yu5a"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://03k48fke03vu" path="res://src/data_viewer/DataViewerRepository.cs" id="1_1cvot"]
|
||||
[ext_resource type="PackedScene" uid="uid://bjg8wyvp8q6oc" path="res://src/enemy/enemy_types/02. michael/MichaelModelView.tscn" id="2_8autu"]
|
||||
[ext_resource type="PackedScene" uid="uid://bli0t0d6ommvi" path="res://src/enemy/enemy_types/01. sproingy/SproingyModelView.tscn" id="3_0bpmu"]
|
||||
|
||||
[node name="DataViewerRepository" type="Node"]
|
||||
script = ExtResource("1_1cvot")
|
||||
_modelsToDisplay = [ExtResource("2_8autu"), ExtResource("3_0bpmu")]
|
||||
|
||||
@@ -25,8 +25,12 @@ public partial class EnemyModelView2D : Node3D, IEnemyModelView
|
||||
|
||||
[Node] public AnimationTree AnimationTree { get; set; } = default!;
|
||||
|
||||
[ExportGroup("Animation Debug")]
|
||||
[Export(PropertyHint.Enum)]
|
||||
[ExportGroup("Enemy Model Properties")]
|
||||
[Export(PropertyHint.Range, "0.0, 1.0")]
|
||||
private float _upperThreshold { get; set; } = 0.5f;
|
||||
[Export(PropertyHint.Range, "-1.0, 0.0")]
|
||||
private float _lowerThreshold { get; set; } = -0.5f;
|
||||
|
||||
EnemyDirection _enemyDirection { get; set; } = EnemyDirection.Forward;
|
||||
|
||||
private AnimationNodeStateMachinePlayback _stateMachine;
|
||||
@@ -36,7 +40,7 @@ public partial class EnemyModelView2D : Node3D, IEnemyModelView
|
||||
_stateMachine = (AnimationNodeStateMachinePlayback)AnimationTree.Get("parameters/playback");
|
||||
}
|
||||
|
||||
public void SetCurrentDirection(Basis enemyBasis, Vector3 cameraDirection) => _enemyDirection = GetEnemyDirection(enemyBasis, cameraDirection, 0.55f, 0.45f);
|
||||
public void SetCurrentDirection(Basis enemyBasis, Vector3 cameraDirection) => _enemyDirection = GetEnemyDirection(enemyBasis, cameraDirection, _upperThreshold, _lowerThreshold);
|
||||
|
||||
public void PlayPrimaryAttackAnimation() => _stateMachine.Travel(_primaryAttackName);
|
||||
|
||||
@@ -78,7 +82,7 @@ public partial class EnemyModelView2D : Node3D, IEnemyModelView
|
||||
var forwardDotProduct = enemyForwardDirection.Dot(cameraDirection);
|
||||
|
||||
// Check if forward facing. If the dot product is -1, the enemy is facing the camera.
|
||||
if (forwardDotProduct < -rotateUpperThreshold)
|
||||
if (forwardDotProduct < _lowerThreshold)
|
||||
{
|
||||
SetForward();
|
||||
return EnemyDirection.Forward;
|
||||
@@ -93,17 +97,17 @@ public partial class EnemyModelView2D : Node3D, IEnemyModelView
|
||||
else
|
||||
{
|
||||
// If the dot product of the perpendicular direction is positive (up to 1), the enemy is facing to the left (since it's mirrored).
|
||||
if (leftDotProduct > 0)
|
||||
if (leftDotProduct < _lowerThreshold)
|
||||
{
|
||||
SetRight();
|
||||
return EnemyDirection.Right;
|
||||
return EnemyDirection.Left;
|
||||
}
|
||||
|
||||
// Check if side facing. If the dot product is close to zero in the positive or negative direction, its close to the threshold for turning.
|
||||
if (Mathf.Abs(forwardDotProduct) < rotateLowerThreshold)
|
||||
if (leftDotProduct > rotateUpperThreshold)
|
||||
{
|
||||
SetLeft();
|
||||
return EnemyDirection.Left;
|
||||
return EnemyDirection.Right;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -796,8 +796,12 @@ switch_mode = 2
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_l2wq1"]
|
||||
reset = false
|
||||
switch_mode = 1
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_jwlar"]
|
||||
reset = false
|
||||
switch_mode = 1
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_fdoul"]
|
||||
|
||||
@@ -812,13 +816,11 @@ states/Walking/position = Vector2(653, 100)
|
||||
transitions = ["Start", "Idle", SubResource("AnimationNodeStateMachineTransition_djeua"), "Idle", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_8wbs7"), "Primary Attack", "Idle", SubResource("AnimationNodeStateMachineTransition_mnr4r"), "Idle", "Walking", SubResource("AnimationNodeStateMachineTransition_l2wq1"), "Walking", "Idle", SubResource("AnimationNodeStateMachineTransition_jwlar"), "Walking", "Primary Attack", SubResource("AnimationNodeStateMachineTransition_fdoul")]
|
||||
|
||||
[node name="EnemyModelView" type="Node3D"]
|
||||
transform = Transform3D(3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0)
|
||||
script = ExtResource("1_oh25a")
|
||||
EnemyLoreInfo = SubResource("Resource_ivy74")
|
||||
_enemyDirection = 1
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 0, 0)
|
||||
transform = Transform3D(6, 0, 0, 0, 6, 0, 0, 0, 6, 0, 0, 0)
|
||||
pixel_size = 0.001
|
||||
billboard = 2
|
||||
shaded = true
|
||||
@@ -846,7 +848,6 @@ material = ExtResource("3_ivy74")
|
||||
position = Vector2(100, 100)
|
||||
sprite_frames = SubResource("SpriteFrames_6drt6")
|
||||
animation = &"idle_left_walk"
|
||||
frame = 6
|
||||
|
||||
[node name="Hitbox" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
||||
@@ -800,12 +800,17 @@ advance_mode = 2
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_ck0ak"]
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_y4gx8"]
|
||||
reset = false
|
||||
switch_mode = 2
|
||||
advance_mode = 2
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_fxhv6"]
|
||||
reset = false
|
||||
switch_mode = 1
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_pxi1p"]
|
||||
reset = false
|
||||
switch_mode = 1
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="AnimationNodeStateMachineTransition_gejfr"]
|
||||
|
||||
@@ -1184,7 +1189,6 @@ animations = [{
|
||||
[node name="EnemyModelView" type="Node3D"]
|
||||
script = ExtResource("1_o4cc2")
|
||||
EnemyLoreInfo = SubResource("Resource_gby04")
|
||||
_enemyDirection = 1
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.086869, 0)
|
||||
|
||||
@@ -7191,7 +7191,7 @@ script = ExtResource("1_ol7va")
|
||||
EnemyLoreInfo = SubResource("Resource_500at")
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 3.13673, 0)
|
||||
transform = Transform3D(1.5, 0, 0, 0, 1.5, 0, 0, 0, 1.5, 0, 1.85151, 0)
|
||||
billboard = 2
|
||||
alpha_cut = 1
|
||||
texture_filter = 0
|
||||
|
||||
Reference in New Issue
Block a user