cringe bug fix im stupid

in HealthHandmer
This commit is contained in:
Crizomb 2025-01-28 11:58:43 +01:00
parent 37bed1fd33
commit f5acd70d85
11 changed files with 135 additions and 53 deletions

View file

@ -8,10 +8,9 @@ using System.Collections.Generic;
public abstract class AbstractBehaviour : MonoBehaviour
{
[SerializeField] private float pathFps = 1.0f;
[SerializeField] private float attackFps = 5.0f;
[SerializeField] protected float distanceGoal = 0.0f;
protected abstract void MoveAction();
protected abstract void AttackAction();
protected MinecraftUnit CurrentMinecraftUnit;
@ -19,23 +18,9 @@ public abstract class AbstractBehaviour : MonoBehaviour
void Start()
{
CurrentMinecraftUnit = GetComponent<MinecraftUnit>();
StartCoroutine(attackUpdate());
StartCoroutine(pathUpdate());
}
// Path update and attack update can be expansive, so we don't do that every frame. We create custom update
// We create custom update at low fps to handle this without performance issues
private IEnumerator attackUpdate()
{
while (true)
{
AttackAction();
yield return new WaitForSeconds(1.0f/attackFps);
}
}
private IEnumerator pathUpdate()
{
while (true)

View file

@ -4,11 +4,20 @@ public class DefensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
throw new System.NotImplementedException();
if (CurrentMinecraftUnit.IsTeamA)
{
if (GlobalsVariable.AliveUnitsTeamB.Count == 0) return;
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenA.transform);
}
else
{
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return;
CurrentMinecraftUnit.MovementHandler.UpdateNearestFrom(GlobalsVariable.QueenB.transform);
}
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
protected override void AttackAction()
{
throw new System.NotImplementedException();
}
}

View file

@ -1,8 +1,8 @@
using System;
using UnityEngine;
public class NeutralBehaviour : AbstractBehaviour
{
[SerializeField] private float distanceGoal = 0.0f;
protected override void MoveAction()
{
if (CurrentMinecraftUnit.IsTeamA)
@ -13,15 +13,14 @@ public class NeutralBehaviour : AbstractBehaviour
{
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return;
}
CurrentMinecraftUnit.MovementHandler.UpdateNearest();
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
AbstractUnit targetUnit = CurrentMinecraftUnit.MovementHandler.TargetUnit;
if (targetUnit == null)
{
return;
}
Vector3 targetPos = targetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
protected override void AttackAction()
{
//CurrentMinecraftUnit.AttackHandler.Attack();
}
}

View file

@ -4,11 +4,19 @@ public class OffensiveBehaviour : AbstractBehaviour
{
protected override void MoveAction()
{
throw new System.NotImplementedException();
}
protected override void AttackAction()
{
throw new System.NotImplementedException();
if (CurrentMinecraftUnit.IsTeamA)
{
if (GlobalsVariable.QueenB == null) return;
}
else
{
if (GlobalsVariable.QueenA == null) return;
}
CurrentMinecraftUnit.MovementHandler.TargetUnit = GlobalsVariable.QueenB;
Vector3 targetPos = CurrentMinecraftUnit.MovementHandler.TargetUnit.transform.position;
Vector3 goalPos = targetPos + (transform.position - targetPos).normalized * distanceGoal;
CurrentMinecraftUnit.MovementHandler.MoveTowards(goalPos);
}
}