mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 02:55:55 +00:00
Face player towards aim direction
This commit is contained in:
parent
8eba34915d
commit
25a9bc1d78
9 changed files with 75 additions and 58 deletions
|
|
@ -1,6 +1,5 @@
|
|||
[gd_resource type="Resource" script_class="EnemyResource" load_steps=4 format=3 uid="uid://cfdvg162u65sr"]
|
||||
[gd_resource type="Resource" script_class="EnemyResource" load_steps=3 format=3 uid="uid://cfdvg162u65sr"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="1_f3huq"]
|
||||
[ext_resource type="Resource" uid="uid://cdfmedtgp2rcn" path="res://Resources/Weapons/EnemyWeapon.tres" id="7_filx8"]
|
||||
[ext_resource type="Script" uid="uid://cd5o0ceb50jki" path="res://Scripts/Resources/EnemyResource.cs" id="8_x8scf"]
|
||||
|
||||
|
|
@ -12,7 +11,7 @@ PrefabPath = &"res://Scenes/Actors/Thermathron.tscn"
|
|||
MaxHealth = 8.0
|
||||
MovementSpeed = 38.0
|
||||
Weapon = ExtResource("7_filx8")
|
||||
LootDrops = Array[ExtResource("1_f3huq")]([])
|
||||
LootDrops = []
|
||||
MotivationReward = 4.0
|
||||
PlayerDetectionRange = 90.0
|
||||
ViewRange = 120.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
[gd_resource type="Resource" script_class="EnemyResource" load_steps=4 format=3 uid="uid://ysd6wl2gmdhn"]
|
||||
[gd_resource type="Resource" script_class="EnemyResource" load_steps=3 format=3 uid="uid://ysd6wl2gmdhn"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cq65aed620ijo" path="res://Scripts/Resources/Loot/LootDrop.cs" id="1_sma76"]
|
||||
[ext_resource type="Resource" uid="uid://dyaxm3st70sh6" path="res://Resources/Weapons/Enemy/TurretWeapon.tres" id="1_yap8t"]
|
||||
[ext_resource type="Script" uid="uid://cd5o0ceb50jki" path="res://Scripts/Resources/EnemyResource.cs" id="2_sma76"]
|
||||
|
||||
|
|
@ -12,7 +11,7 @@ PrefabPath = &"res://Scenes/Actors/Turret360.tscn"
|
|||
MaxHealth = 14.0
|
||||
MovementSpeed = 0.0
|
||||
Weapon = ExtResource("1_yap8t")
|
||||
LootDrops = Array[ExtResource("1_sma76")]([])
|
||||
LootDrops = []
|
||||
MotivationReward = 4.0
|
||||
PlayerDetectionRange = 90.0
|
||||
ViewRange = 120.0
|
||||
|
|
|
|||
|
|
@ -13,5 +13,5 @@
|
|||
script = ExtResource("1_fmydh")
|
||||
EggIndex = 0
|
||||
StartingEquipment = Array[ExtResource("1_xjbmv")]([ExtResource("1_juefn"), ExtResource("2_xjbmv")])
|
||||
RemoveEquipment = [ExtResource("1_wchkt"), ExtResource("2_2v4s6"), ExtResource("3_73lvc"), ExtResource("4_vnxsw")]
|
||||
RemoveEquipment = Array[ExtResource("1_xjbmv")]([ExtResource("1_wchkt"), ExtResource("2_2v4s6"), ExtResource("3_73lvc"), ExtResource("4_vnxsw")])
|
||||
metadata/_custom_type_script = "uid://mja0rk7n2kln"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=152 format=4 uid="uid://bv451a8wgty4u"]
|
||||
[gd_scene load_steps=153 format=4 uid="uid://bv451a8wgty4u"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://doxmbokehw8ci" path="res://Scripts/GameManager.cs" id="1_8tmoj"]
|
||||
[ext_resource type="PackedScene" uid="uid://c4pr2707hbeph" path="res://Scenes/Actors/fsm_player.tscn" id="2_ksslq"]
|
||||
|
|
@ -74,6 +74,7 @@
|
|||
[ext_resource type="PackedScene" uid="uid://c5fiv1nioghfb" path="res://Scenes/Actors/Marisa.tscn" id="50_mp5ma"]
|
||||
[ext_resource type="Resource" uid="uid://37h0tjja4sns" path="res://Resources/Maps/RebelBase.tres" id="52_orkt3"]
|
||||
[ext_resource type="PackedScene" uid="uid://bqjcwxene73l2" path="res://Scenes/Actors/ActorEnemyTest.tscn" id="55_chha6"]
|
||||
[ext_resource type="Script" uid="uid://b5fesrd4lv8t1" path="res://Scripts/Resources/Events/EventResource.cs" id="55_dferh"]
|
||||
[ext_resource type="PackedScene" uid="uid://bjskkeb3ppcs8" path="res://Scenes/Actors/Turret360.tscn" id="62_h0jm4"]
|
||||
[ext_resource type="Script" uid="uid://v57xjmhi28kw" path="res://Scripts/Resources/Events/ControlActorEvent.cs" id="64_rphi8"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0gpbkxdfbnjh" path="res://Scenes/Actors/ForceField_Horizontal.tscn" id="66_nxn3h"]
|
||||
|
|
@ -268,7 +269,7 @@ ActivationType = 0
|
|||
Targets = Array[NodePath]([NodePath("../Rumia")])
|
||||
WaitForCompletion = true
|
||||
|
||||
[sub_resource type="Resource" id="Resource_j86ly"]
|
||||
[sub_resource type="Resource" id="Resource_fuaed"]
|
||||
resource_local_to_scene = true
|
||||
script = ExtResource("49_0si7g")
|
||||
Target = NodePath(".")
|
||||
|
|
@ -717,7 +718,7 @@ Invisible = true
|
|||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="ScriptableAreaTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps/DebugTeleporter" instance=ExtResource("43_kf3qc")]
|
||||
Events = [SubResource("Resource_usuub")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_usuub")])
|
||||
|
||||
[node name="BlueKeycard2" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("35_rblsn")]
|
||||
position = Vector2(-1032, -317)
|
||||
|
|
@ -914,7 +915,7 @@ position = Vector2(-1423, -188)
|
|||
[node name="LevelStartTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-762, -129)
|
||||
scale = Vector2(1.455, 1.455)
|
||||
Events = [SubResource("Resource_5er5x"), SubResource("Resource_b25hy")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_5er5x"), SubResource("Resource_b25hy")])
|
||||
|
||||
[node name="AreaTrigger2" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("28_6au4t")]
|
||||
position = Vector2(-435, -162)
|
||||
|
|
@ -957,7 +958,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer2"]
|
||||
position = Vector2(120, 25)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_wma5c")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_wma5c")])
|
||||
|
||||
[node name="Computer6" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1113, -139)
|
||||
|
|
@ -967,7 +968,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Script2" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer6"]
|
||||
position = Vector2(0, 1)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_cxj4w")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_cxj4w")])
|
||||
|
||||
[node name="Computer7" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1175.36, 213.708)
|
||||
|
|
@ -978,7 +979,7 @@ metadata/_edit_group_ = true
|
|||
[node name="Computer7Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer7"]
|
||||
position = Vector2(0, 1)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_tcc7d")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_tcc7d")])
|
||||
|
||||
[node name="Computer5" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-1344, -251)
|
||||
|
|
@ -986,7 +987,7 @@ Targets = [NodePath("Computer5Script")]
|
|||
|
||||
[node name="Computer5Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer5"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_fasrq"), SubResource("Resource_mah4x"), SubResource("Resource_0bqta")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_fasrq"), SubResource("Resource_mah4x"), SubResource("Resource_0bqta")])
|
||||
|
||||
[node name="Computer3" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-612.57, -358.528)
|
||||
|
|
@ -994,7 +995,7 @@ Target = NodePath("Script")
|
|||
|
||||
[node name="Script" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer3"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_o2kpk")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_o2kpk")])
|
||||
|
||||
[node name="Computer4" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Target") instance=ExtResource("31_243ec")]
|
||||
position = Vector2(-791, -505)
|
||||
|
|
@ -1002,7 +1003,7 @@ Target = NodePath("Node2D")
|
|||
|
||||
[node name="Node2D" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_s3g2w")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_s3g2w")])
|
||||
|
||||
[node name="Label" type="Label" parent="Parallax2D/Factory Tilemaps/LevelProps/Computer4"]
|
||||
offset_left = -5.0
|
||||
|
|
@ -1031,11 +1032,11 @@ position = Vector2(-792, -407)
|
|||
[node name="BossBattleEndScript" type="Node2D" parent="Parallax2D/Factory Tilemaps/LevelProps"]
|
||||
position = Vector2(-1628.53, -477.628)
|
||||
script = ExtResource("42_wigyb")
|
||||
Events = [SubResource("Resource_068l7"), SubResource("Resource_l3nop")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_068l7"), SubResource("Resource_l3nop")])
|
||||
|
||||
[node name="BossBattleStartScript" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-1487, -396)
|
||||
Events = [SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_j86ly")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_4f4id"), SubResource("Resource_s2o7m"), SubResource("Resource_b1dht"), SubResource("Resource_xrgpy"), SubResource("Resource_fuaed")])
|
||||
|
||||
[node name="Enemy13" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("47_u1ve6")]
|
||||
position = Vector2(-1657, -788)
|
||||
|
|
@ -1162,7 +1163,7 @@ position = Vector2(-2000, -736)
|
|||
[node name="ControlPad8" parent="Parallax2D/Factory Tilemaps/LevelProps" node_paths=PackedStringArray("Targets") instance=ExtResource("12_hfkf1")]
|
||||
position = Vector2(-2027, -735)
|
||||
Targets = [NodePath("../HorizontalForceField")]
|
||||
Requirements = [ExtResource("84_ma1ta")]
|
||||
Requirements = Array[ExtResource("6_8tdlb")]([ExtResource("84_ma1ta")])
|
||||
|
||||
[node name="Ammo6" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("34_17pjh")]
|
||||
position = Vector2(-872, -220)
|
||||
|
|
@ -1324,7 +1325,7 @@ position = Vector2(-2072, -211)
|
|||
|
||||
[node name="ScriptableAreaTrigger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("43_kf3qc")]
|
||||
position = Vector2(-2063, -232)
|
||||
Events = [SubResource("Resource_l476f"), SubResource("Resource_dskij")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_l476f"), SubResource("Resource_dskij")])
|
||||
|
||||
[node name="ShieldExtendPickup" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("103_0bqta")]
|
||||
position = Vector2(-1646, 38)
|
||||
|
|
@ -1452,7 +1453,7 @@ position = Vector2(-1633, 391)
|
|||
|
||||
[node name="MovementSensorLonger" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("112_j86ly")]
|
||||
position = Vector2(-1495, 516)
|
||||
Events = [SubResource("Resource_uslvo")]
|
||||
Events = Array[ExtResource("55_dferh")]([SubResource("Resource_uslvo")])
|
||||
|
||||
[node name="WallEmitter" parent="Parallax2D/Factory Tilemaps/LevelProps" instance=ExtResource("113_dferh")]
|
||||
position = Vector2(-1480, 451)
|
||||
|
|
|
|||
|
|
@ -53,42 +53,56 @@ public partial class PlayerAnimationProvider : Node2D
|
|||
{
|
||||
_animatedSprite.Hide();
|
||||
}
|
||||
|
||||
public void SetAnimation(Vector2 velocity)
|
||||
{
|
||||
if (velocity.Length() == 0)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (velocity.Length() > 40)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0.8f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (velocity.X > 0)
|
||||
public void SetAnimationSpeed(Vector2 velocity)
|
||||
{
|
||||
if (velocity.Length() == 0)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (velocity.Length() > 40)
|
||||
{
|
||||
_animatedSprite.SpeedScale = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_animatedSprite.SpeedScale = 0.8f;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAnimation(Vector2 direction)
|
||||
{
|
||||
if (direction == Vector2.Zero)
|
||||
return;
|
||||
|
||||
float angle = Mathf.RadToDeg(direction.Angle());
|
||||
|
||||
// Normalize to 0-360
|
||||
if (angle < 0)
|
||||
angle += 360;
|
||||
|
||||
string animToPlay;
|
||||
|
||||
switch (angle)
|
||||
{
|
||||
_animatedSprite.Play(WalkRightAnimationName);
|
||||
}
|
||||
else if (velocity.X < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkLeftAnimationName);
|
||||
}
|
||||
else if (velocity.Y > 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkDownAnimationName);
|
||||
}
|
||||
else if (velocity.Y < 0)
|
||||
{
|
||||
_animatedSprite.Play(WalkUpAnimationName);
|
||||
case >= 45 and < 135:
|
||||
_animatedSprite.Play(WalkDownAnimationName);
|
||||
break;
|
||||
case >= 135 and < 225:
|
||||
_animatedSprite.Play(WalkLeftAnimationName);
|
||||
break;
|
||||
case >= 225 and < 315:
|
||||
_animatedSprite.Play(WalkUpAnimationName);
|
||||
break;
|
||||
default:
|
||||
_animatedSprite.Play(WalkRightAnimationName);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Blink()
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public partial class AnimationModule : ModuleBase<EnemyState, CharacterBody2D>
|
|||
|
||||
public override void EnterState(EnemyState state)
|
||||
{
|
||||
AnimationProvider.SetAnimation(StorageModule.FacingDirection);
|
||||
AnimationProvider.SetAnimation(StorageModule.AimingDirection);
|
||||
AnimationProvider.SetAnimation(Vector2.Zero);
|
||||
}
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ public partial class AnimationModule : ModuleBase<EnemyState, CharacterBody2D>
|
|||
|
||||
public override void Process(double delta)
|
||||
{
|
||||
AnimationProvider.SetAnimation(StorageModule.FacingDirection);
|
||||
AnimationProvider.SetAnimation(StorageModule.AimingDirection);
|
||||
|
||||
if (_machine.MainObject.Velocity == Vector2.Zero)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -98,7 +98,8 @@ public partial class Active : PlayerStateBase
|
|||
public override void ExitState()
|
||||
{
|
||||
base.ExitState();
|
||||
_animationProvider.SetAnimation(Vector2.Zero);
|
||||
_animationProvider.SetAnimationSpeed(Vector2.Zero);
|
||||
//_animationProvider.SetAnimation(Vector2.Zero);
|
||||
_crosshairProvider.Hide();
|
||||
_hitboxSpriteProvider.Hide();
|
||||
|
||||
|
|
@ -147,7 +148,8 @@ public partial class Active : PlayerStateBase
|
|||
}
|
||||
// }
|
||||
|
||||
_animationProvider.SetAnimation(MainObject.Velocity);
|
||||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(FacingDirection);
|
||||
|
||||
_crosshairProvider.UpdatePosition(FacingDirection);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ public partial class Cutscene : PlayerStateBase
|
|||
|
||||
public override void ExitState()
|
||||
{
|
||||
_animationProvider.SetAnimation(Vector2.Zero);
|
||||
_animationProvider.SetAnimationSpeed(Vector2.Zero);
|
||||
}
|
||||
|
||||
public override void ProcessState(double delta)
|
||||
{
|
||||
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
|
||||
_animationProvider.SetAnimation(MainObject.Velocity);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@ public partial class PlayerStorageModule : Node2D
|
|||
public PlayerFSMProxy Root { get; private set; }
|
||||
public Node2D RootAsNode => Root;
|
||||
public Vector2 FacingDirection { get; set; }
|
||||
public Vector2 AimingDirection { get; set; }
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue