cringe bug fix im stupid
in HealthHandmer
This commit is contained in:
parent
37bed1fd33
commit
f5acd70d85
11 changed files with 135 additions and 53 deletions
|
@ -21,7 +21,6 @@ public class AttackProjectile : AttackHandler
|
|||
{
|
||||
if (GlobalsVariable.AliveUnitsTeamA.Count == 0) return false;
|
||||
}
|
||||
_minecraftUnit.MovementHandler.UpdateNearest();
|
||||
}
|
||||
float launchAngle = findLaunchAngle();
|
||||
//print(launchAngle);
|
||||
|
@ -47,6 +46,7 @@ public class AttackProjectile : AttackHandler
|
|||
// Source : https://en.wikipedia.org/wiki/Projectile_motion#Angle_%CE%B8_required_to_hit_coordinate_(x,_y)
|
||||
|
||||
AbstractUnit targetUnit = _minecraftUnit.MovementHandler.TargetUnit;
|
||||
if (targetUnit == null) return -1f;
|
||||
Vector3 diffVector = targetUnit.transform.position - spawnPos.position;
|
||||
Vector3 projectOnPlane = Vector3.ProjectOnPlane(diffVector, Vector3.up);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ public class WitchSummon : BaseCapacity
|
|||
|
||||
protected override bool CapacityCall()
|
||||
{
|
||||
print("SUMMON");
|
||||
print(Mana);
|
||||
Instantiate(summonUnit, transform.position, Quaternion.identity);
|
||||
GameObject unit = Instantiate(summonUnit, transform.position, Quaternion.identity);
|
||||
AbstractUnit unitScript = unit.GetComponent<AbstractUnit>();
|
||||
unitScript.StartFight();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class HealthHandler : MonoBehaviour
|
|||
if (deathState == DeathSate.NotImportant)
|
||||
{
|
||||
Destroy(gameObject, delay);
|
||||
return;
|
||||
}
|
||||
|
||||
GlobalsVariable.AliveUnitsTeamB = new List<AbstractUnit>();
|
||||
|
|
|
@ -15,7 +15,7 @@ public class MovementHandler : MonoBehaviour
|
|||
[SerializeField] private float knockbackTime = 1.2f;
|
||||
private float _noNavMeshDeadTime = 6.0f;
|
||||
|
||||
[HideInInspector] public AbstractUnit TargetUnit {get; private set; }
|
||||
[HideInInspector] public AbstractUnit TargetUnit {get; set; }
|
||||
|
||||
private MinecraftUnit _minecraftUnit;
|
||||
private Rigidbody _rigidbody;
|
||||
|
@ -62,24 +62,25 @@ public class MovementHandler : MonoBehaviour
|
|||
TargetUnit = FindNearest(followEnemy);
|
||||
}
|
||||
|
||||
public void MoveTowardsNearest()
|
||||
public void UpdateNearestFrom(Transform transform)
|
||||
{
|
||||
MoveTowards(TargetUnit.transform.position);
|
||||
TargetUnit = FindNearestFromTransform(true, transform);
|
||||
}
|
||||
|
||||
|
||||
// If findEnemy, return closest ennemy else return closest ally
|
||||
public AbstractUnit FindNearest(bool findEnemy)
|
||||
private AbstractUnit FindNearestFromTransform(bool findEnemy, Transform from)
|
||||
{
|
||||
// Funny funny double ternary operator.
|
||||
List<AbstractUnit> targets = findEnemy ?
|
||||
_minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA
|
||||
_minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamB : GlobalsVariable.AliveUnitsTeamA
|
||||
: _minecraftUnit.IsTeamA ? GlobalsVariable.AliveUnitsTeamA : GlobalsVariable.AliveUnitsTeamB;
|
||||
|
||||
AbstractUnit closestUnit = null;
|
||||
float closestDistance = float.MaxValue;
|
||||
foreach (AbstractUnit target in targets)
|
||||
{
|
||||
float distanceToEnemy = (target.transform.position - transform.position).sqrMagnitude;
|
||||
float distanceToEnemy = (target.transform.position - from.position).sqrMagnitude;
|
||||
if (distanceToEnemy < closestDistance && target != _minecraftUnit)
|
||||
{
|
||||
closestUnit = target;
|
||||
|
@ -87,8 +88,20 @@ public class MovementHandler : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
if (closestUnit == null)
|
||||
{
|
||||
print("What");
|
||||
print(targets.Count);
|
||||
print(targets);
|
||||
}
|
||||
|
||||
return closestUnit;
|
||||
}
|
||||
|
||||
private AbstractUnit FindNearest(bool findEnemy)
|
||||
{
|
||||
return FindNearestFromTransform(findEnemy, transform);
|
||||
}
|
||||
|
||||
public IEnumerator TakeImpulse(Vector3 impulse)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue