Created
November 15, 2019 10:15
-
-
Save nathancyam/505a60d814bc37da381c40d3c8f2cc02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
namespace EnemyBehaviour | |
{ | |
public class Attack : IEnemyBehaviour | |
{ | |
public EnemyController EnemyCtrl | |
{ | |
get => mobile.m_EnemyController; | |
} | |
EnemyMobile mobile; | |
GameObject gameObject; | |
private Vector3 LastKnownPlayerPosition | |
{ | |
get => EnemyCtrl.knownDetectedTarget.transform.position; | |
} | |
public Attack(EnemyMobile enemy) | |
{ | |
mobile = enemy; | |
gameObject = mobile.gameObject; | |
} | |
public void UpdateCurrentAIState() | |
{ | |
if (Vector3.Distance(LastKnownPlayerPosition, EnemyCtrl.detectionSourcePoint.position) >= (mobile.attackStopDistanceRatio * EnemyCtrl.attackRange)) | |
{ | |
EnemyCtrl.SetNavDestination(LastKnownPlayerPosition); | |
} | |
else | |
{ | |
EnemyCtrl.SetNavDestination(gameObject.transform.position); | |
} | |
EnemyCtrl.OrientTowards(LastKnownPlayerPosition); | |
EnemyCtrl.TryAtack((LastKnownPlayerPosition - EnemyCtrl.weapon.transform.position).normalized); | |
} | |
public IEnemyBehaviour UpdateAIStateTransitions() | |
{ | |
if (!EnemyCtrl.isTargetInAttackRange) | |
{ | |
return new Follow(mobile); | |
} | |
return this; | |
} | |
} | |
public class Follow : IEnemyBehaviour | |
{ | |
public EnemyController EnemyCtrl | |
{ | |
get => mobile.m_EnemyController; | |
} | |
public GameObject gameObject; | |
EnemyMobile mobile; | |
private Vector3 LastKnownPlayerPosition | |
{ | |
get => EnemyCtrl.knownDetectedTarget.transform.position; | |
} | |
public Follow(EnemyMobile enemy) | |
{ | |
mobile = enemy; | |
gameObject = mobile.gameObject; | |
} | |
public void UpdateCurrentAIState() | |
{ | |
EnemyCtrl.SetNavDestination(LastKnownPlayerPosition); | |
EnemyCtrl.OrientTowards(LastKnownPlayerPosition); | |
} | |
public IEnemyBehaviour UpdateAIStateTransitions() | |
{ | |
if (EnemyCtrl.isSeeingTarget && EnemyCtrl.isTargetInAttackRange) | |
{ | |
return new Attack(mobile); | |
} | |
return this; | |
} | |
} | |
public class Patrol : IEnemyBehaviour | |
{ | |
public EnemyController EnemyCtrl | |
{ | |
get => mobile.m_EnemyController; | |
} | |
GameObject gameObject; | |
EnemyMobile mobile; | |
public Patrol(EnemyMobile enemy) | |
{ | |
mobile = enemy; | |
gameObject = mobile.gameObject; | |
} | |
public void UpdateCurrentAIState() | |
{ | |
EnemyCtrl.UpdatePathDestination(); | |
EnemyCtrl.SetNavDestination(EnemyCtrl.GetDestinationOnPath()); | |
} | |
public IEnemyBehaviour UpdateAIStateTransitions() | |
{ | |
return this; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment