some damage interfacing
This commit is contained in:
@@ -3,13 +3,16 @@ using System;
|
||||
using Movementtests.interfaces;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable
|
||||
public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKnockbackable, IDamageMaker
|
||||
{
|
||||
[Export]
|
||||
public Node3D Target { get; set; }
|
||||
|
||||
[Export]
|
||||
public FlyingEnemyInputs Inputs;
|
||||
public FlyingEnemyInputs Inputs { get; set; }
|
||||
|
||||
[Export]
|
||||
public RDamage GetDamageDealt { get; set; }
|
||||
|
||||
private RayCast3D _groundDistanceRaycast;
|
||||
private Area3D _damageBox;
|
||||
@@ -20,7 +23,7 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
public override void _Ready()
|
||||
{
|
||||
_groundDistanceRaycast = GetNode<RayCast3D>("GroundDistance");
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, -Inputs.TargetHeight, 0);
|
||||
_groundDistanceRaycast.TargetPosition = new Vector3(0, 0, 0);
|
||||
|
||||
_damageBox = GetNode<Area3D>("DamageBox");
|
||||
_damageBox.BodyEntered += OnDamageBoxTriggered;
|
||||
@@ -28,26 +31,20 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
_randomDirection = new Vector3(GD.RandRange(-1, 1), 1, GD.RandRange(-1, 1)).Normalized();
|
||||
}
|
||||
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
if(body is IDamageable damageable) damageable.TakeDamage();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var target = Target.GlobalPosition;
|
||||
var direction = (target - GlobalPosition).Normalized();
|
||||
Vector3 velocity = Velocity;
|
||||
|
||||
var targetPlane = new Vector3(target.X, GlobalPosition.Y, target.Z);
|
||||
LookAt(targetPlane);
|
||||
LookAt(target);
|
||||
|
||||
// Check if we have a direct line of sight to the player
|
||||
if (!_movingToDesiredHeight)
|
||||
{
|
||||
velocity = direction * Inputs.Speed;
|
||||
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count > 0)
|
||||
@@ -60,11 +57,12 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
{
|
||||
velocity = _randomDirection * Inputs.Speed;
|
||||
|
||||
if (!_groundDistanceRaycast.IsColliding())
|
||||
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 spaceState = GetWorld3D().DirectSpaceState;
|
||||
var query = PhysicsRayQueryParameters3D.Create(GlobalPosition, target, _groundDistanceRaycast.CollisionMask);
|
||||
var result = spaceState.IntersectRay(query);
|
||||
if (result.Count == 0)
|
||||
@@ -78,8 +76,13 @@ public partial class FlyingEnemy : CharacterBody3D, IDamageable, IKillable, IKno
|
||||
MoveAndSlide();
|
||||
}
|
||||
|
||||
public void TakeDamage()
|
||||
public void OnDamageBoxTriggered(Node3D body)
|
||||
{
|
||||
GD.Print("Oh no I'm falling");
|
||||
if(body is IDamageable damageable) damageable.TakeDamage(GetDamageDealt);
|
||||
}
|
||||
|
||||
public void TakeDamage(RDamage damage)
|
||||
{
|
||||
GD.Print("Oh no I'm falling!", damage.DamageDealt);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user