removing broken ABC and refactoring enemy movement
All checks were successful
Create tag and build when new code gets to main / BumpTag (push) Successful in 19s
Create tag and build when new code gets to main / Export (push) Successful in 10m2s

This commit is contained in:
2026-01-17 19:55:51 +01:00
parent f7705a6d57
commit 7c74b8b5e5
24 changed files with 211 additions and 286 deletions

View File

@@ -1,116 +0,0 @@
using Godot;
using System;
using Movementtests.interfaces;
[GlobalClass]
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IHealthable, IKnockbackable, IDamageMaker
{
[Export]
public Node3D Target { get; set; }
[Export]
public FlyingEnemyInputs Inputs { get; set; }
[Export]
public RDamage GetDamageDealt { get; set; }
[Export]
public CHealth CHealth { get; set; }
[Export]
public CDamageable CDamage { get; set; }
[Export]
public RDeathEffect[] DeathEffects { get; set; }
private RayCast3D _groundDistanceRaycast;
private Area3D _damageBox;
private bool _movingToDesiredHeight = true;
private Vector3 _randomDirection;
public override void _Ready()
{
_groundDistanceRaycast = GetNode<RayCast3D>("GroundDistance");
_groundDistanceRaycast.TargetPosition = new Vector3(0, 0, 0);
_damageBox = GetNode<Area3D>("DamageBox");
_damageBox.BodyEntered += OnDamageBoxTriggered;
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
CDamage.DamageTaken += ReduceHealth;
CHealth.Dead += Kill;
}
public override void _PhysicsProcess(double delta)
{
var spaceState = GetWorld3D().DirectSpaceState;
var target = Target.GlobalPosition;
var direction = (target - GlobalPosition).Normalized();
Vector3 velocity = Velocity;
LookAt(target);
// Check if we have a direct line of sight to the player
if (!_movingToDesiredHeight)
{
velocity = direction * Inputs.Speed;
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
var result = spaceState.IntersectRay(query);
if (result.Count > 0)
{
_movingToDesiredHeight = true;
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
}
}
else
{
velocity = _randomDirection * Inputs.Speed;
var groundQuery = PhysicsRayQueryParameters3D.Create(GlobalPosition, GlobalPosition+Vector3.Down*Inputs.TargetHeight, _groundDistanceRaycast.CollisionMask);
var groundResult = spaceState.IntersectRay(groundQuery);
if (groundResult.Count == 0)
{
velocity.Y = 0;
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
var result = spaceState.IntersectRay(query);
if (result.Count == 0)
{
_movingToDesiredHeight = false;
}
}
}
Velocity = velocity;
MoveAndSlide();
}
public void OnDamageBoxTriggered(Node3D body)
{
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
}
public event Action<float> DamageTaken;
public float TakeDamage(RDamage damage)
{
return CDamage.TakeDamage(damage);
}
public void ReduceHealth(float amount)
{
CHealth.ReduceHealth(amount);
}
public void Kill()
{
foreach (var killable in DeathEffects.ToIKillables())
{
killable.Kill();
}
QueueFree();
}
}

View File

@@ -1 +0,0 @@
uid://cmvep0qi7qlvf

View File

@@ -1,23 +0,0 @@
using Godot;
using System;
[GlobalClass]
public partial class FlyingEnemyInputs : Resource
{
[Export(PropertyHint.Range, "0,10,0.1,or_greater")]
public float Speed;
[Export(PropertyHint.Range, "0,100,1,or_greater")]
public float TargetHeight;
public FlyingEnemyInputs()
{
Speed = 5.0f;
TargetHeight = 50.0f;
}
public FlyingEnemyInputs(float speed, float targetHeight)
{
Speed = speed;
TargetHeight = targetHeight;
}
}

View File

@@ -1 +0,0 @@
uid://do0dic4r3ri0s

View File

@@ -1,30 +1,14 @@
[gd_scene load_steps=20 format=3 uid="uid://cmlud1hwkd6sv"]
[gd_scene load_steps=18 format=3 uid="uid://cmlud1hwkd6sv"]
[ext_resource type="Script" uid="uid://cmvep0qi7qlvf" path="res://scenes/enemies/flying_enemy/FlyingEnemy.cs" id="1_b46rq"]
[ext_resource type="Script" uid="uid://bn7sc6id7n166" path="res://scenes/enemies/Enemy.cs" id="1_q8l7o"]
[ext_resource type="Script" uid="uid://b6y3ugfydvch0" path="res://resource_definitions/RDamageModifier.cs" id="2_1bsgx"]
[ext_resource type="Script" uid="uid://do0dic4r3ri0s" path="res://scenes/enemies/flying_enemy/FlyingEnemyInputs.cs" id="2_aarbi"]
[ext_resource type="Script" uid="uid://jitubgv6judn" path="res://resource_definitions/RDamage.cs" id="2_irbqc"]
[ext_resource type="Script" uid="uid://b4cwruitopcee" path="res://resource_definitions/RDeathEffect.cs" id="4_12h4s"]
[ext_resource type="Resource" uid="uid://dgo65k2ceqfvy" path="res://scenes/enemies/flying_enemy/flying_enemy_damage.tres" id="2_on7rt"]
[ext_resource type="Script" uid="uid://bjwrpv3jpsc1e" path="res://scenes/health/CHealth.cs" id="4_ys4jv"]
[ext_resource type="Script" uid="uid://baiapod3csndf" path="res://resource_definitions/RHealth.cs" id="5_irbqc"]
[ext_resource type="PackedScene" uid="uid://dmw5ibwrb483f" path="res://scenes/movement/CFlyingMovement.tscn" id="7_vaeds"]
[ext_resource type="Script" uid="uid://dtpxijlnb2c5" path="res://resource_definitions/RMovement.cs" id="8_on7rt"]
[ext_resource type="Script" uid="uid://b0u23nkpaimyc" path="res://scenes/damage/CDamageable.cs" id="8_uotso"]
[sub_resource type="Resource" id="Resource_7nxyi"]
script = ExtResource("2_aarbi")
Speed = 5.0
TargetHeight = 10.0
metadata/_custom_type_script = "uid://do0dic4r3ri0s"
[sub_resource type="Resource" id="Resource_o3msb"]
script = ExtResource("2_irbqc")
DamageDealt = 2.0
DamageType = 2
metadata/_custom_type_script = "uid://jitubgv6judn"
[sub_resource type="Resource" id="Resource_ys4jv"]
script = ExtResource("4_12h4s")
metadata/_custom_type_script = "uid://b4cwruitopcee"
[sub_resource type="Resource" id="Resource_aarbi"]
script = ExtResource("5_irbqc")
StartingHealth = 50.0
@@ -39,6 +23,12 @@ script = ExtResource("2_1bsgx")
DamageType = 1
metadata/_custom_type_script = "uid://b6y3ugfydvch0"
[sub_resource type="Resource" id="Resource_ma2bq"]
script = ExtResource("8_on7rt")
Speed = 2.0
TargetHeight = 10.0
metadata/_custom_type_script = "uid://dtpxijlnb2c5"
[sub_resource type="SphereShape3D" id="SphereShape3D_b46rq"]
[sub_resource type="SphereMesh" id="SphereMesh_1bsgx"]
@@ -55,16 +45,16 @@ albedo_color = Color(0.06469653, 0.06469653, 0.06469653, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_4yfjf"]
size = Vector3(1, 1, 1.5)
[node name="FlyingEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage")]
[node name="FlyingEnemy" type="CharacterBody3D" node_paths=PackedStringArray("CHealth", "CDamage", "CMovement")]
collision_layer = 16
collision_mask = 273
motion_mode = 1
script = ExtResource("1_b46rq")
Inputs = SubResource("Resource_7nxyi")
GetDamageDealt = SubResource("Resource_o3msb")
script = ExtResource("1_q8l7o")
GetDamageDealt = ExtResource("2_on7rt")
CHealth = NodePath("CHealth")
CDamage = NodePath("CDamageable")
DeathEffects = Array[Object]([SubResource("Resource_ys4jv")])
CMovement = NodePath("CFlyingMovement")
DeathEffects = Array[Object]([])
[node name="CHealth" type="Node" parent="."]
script = ExtResource("4_ys4jv")
@@ -76,6 +66,10 @@ script = ExtResource("8_uotso")
DamageModifiers = Array[Object]([SubResource("Resource_jnv07"), SubResource("Resource_53j1c")])
metadata/_custom_type_script = "uid://b0u23nkpaimyc"
[node name="CFlyingMovement" parent="." instance=ExtResource("7_vaeds")]
RMovement = SubResource("Resource_ma2bq")
TerrainCollision = 256
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_b46rq")