Line of sight for enemy
This commit is contained in:
@@ -17,6 +17,8 @@ public interface IEnemy : ICharacterBody3D
|
||||
public EnemyStatInfo EnemyStatInfo { get; set; }
|
||||
|
||||
public NavigationAgent3D NavAgent { get; set; }
|
||||
|
||||
public Area3D LineOfSight { get; set; }
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
@@ -43,6 +45,8 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
|
||||
[Node] public NavigationAgent3D NavAgent { get; set; } = default!;
|
||||
|
||||
[Node] public Area3D LineOfSight { get; set; } = default!;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
EnemyLogic = new EnemyLogic();
|
||||
@@ -55,6 +59,12 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
||||
{
|
||||
CurrentHP = new AutoProp<double>(EnemyStatInfo.MaximumHP);
|
||||
CurrentHP.Sync += OnHPChanged;
|
||||
LineOfSight.BodyEntered += LineOfSight_BodyEntered;
|
||||
}
|
||||
|
||||
private void LineOfSight_BodyEntered(Node3D body)
|
||||
{
|
||||
EnemyLogic.Input(new EnemyLogic.Input.Alerted());
|
||||
}
|
||||
|
||||
public void OnResolved()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=9 format=4 uid="uid://dcgj5i52i76gj"]
|
||||
[gd_scene load_steps=10 format=4 uid="uid://dcgj5i52i76gj"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/enemy/Enemy.cs" id="1_jw471"]
|
||||
[ext_resource type="Resource" uid="uid://c8h26ip4ly18r" path="res://src/enemy/enemy_types/floating_enemy/FloatingEnemy.tres" id="2_ewaf6"]
|
||||
@@ -104,6 +104,10 @@ shadow_mesh = SubResource("ArrayMesh_2wch8")
|
||||
radius = 0.2
|
||||
height = 1.0
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_jbgmx"]
|
||||
height = 3.0
|
||||
radius = 1.0
|
||||
|
||||
[node name="EnemyGuy" type="CharacterBody3D"]
|
||||
collision_layer = 10
|
||||
collision_mask = 9
|
||||
@@ -126,3 +130,12 @@ debug_path_custom_color = Color(1, 0, 0, 1)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("CapsuleShape3D_cwfph")
|
||||
|
||||
[node name="LineOfSight" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 2
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="LineOfSight"]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.0745088, 0.99722, 0, -0.99722, 0.0745088, 0, 0, -1.46944)
|
||||
shape = SubResource("CylinderShape3D_jbgmx")
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace GameJamDungeon
|
||||
enemy.LookAt(new Vector3(gameRepo.PlayerGlobalPosition.Value.X, enemy.GlobalPosition.Y, gameRepo.PlayerGlobalPosition.Value.Z), Vector3.Up);
|
||||
return ToSelf();
|
||||
}
|
||||
|
||||
if (enemy.GlobalPosition.DistanceTo(gameRepo.PlayerGlobalPosition.Value) > 20f)
|
||||
{
|
||||
return To<Idle>();
|
||||
}
|
||||
|
||||
enemy.NavAgent.TargetPosition = gameRepo.PlayerGlobalPosition.Value;
|
||||
var nextPosition = enemy.NavAgent.GetNextPathPosition();
|
||||
var lookAtPos = enemy.NavAgent.GetNextPathPosition();
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace GameJamDungeon
|
||||
public InventoryOpened()
|
||||
{
|
||||
this.OnEnter(() => { Get<IGameRepo>().Pause(); Output(new Output.SetInventoryMode(Get<IGameRepo>().InventoryItems.Value)); });
|
||||
this.OnExit(() => { Output(new Output.HideInventory()); });
|
||||
this.OnExit(() => { Get<IGameRepo>().Resume(); Output(new Output.HideInventory()); });
|
||||
}
|
||||
public Transition On(in Input.InventoryMenuButtonPressed input) => To<Playing>();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace GameJamDungeon
|
||||
public MinimapOpen()
|
||||
{
|
||||
this.OnEnter(() => { Get<IGameRepo>().Pause(); Output(new Output.ShowMiniMap()); });
|
||||
this.OnExit(() => { Output(new Output.HideMiniMap()); });
|
||||
this.OnExit(() => { Get<IGameRepo>().Resume(); Output(new Output.HideMiniMap()); });
|
||||
}
|
||||
|
||||
public Transition On(in Input.MiniMapButtonReleased input) => To<Playing>();
|
||||
|
||||
Reference in New Issue
Block a user