Gladiator roam when vamp is safe and no monster

This commit is contained in:
Soulaha Balde 2022-04-02 14:41:47 -04:00
parent bdd20faaa8
commit e4a304fdba
9 changed files with 320 additions and 13 deletions

View File

@ -1760,4 +1760,4 @@ MonoBehaviour:
- {x: -10, y: -10, z: 0} - {x: -10, y: -10, z: 0}
- {x: 10, y: -10, z: 0} - {x: 10, y: -10, z: 0}
stats: {fileID: 11400000, guid: fe319ad8c9a37b84e8b45268c913d54c, type: 2} stats: {fileID: 11400000, guid: fe319ad8c9a37b84e8b45268c913d54c, type: 2}
monsterPrefab: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} entityPrefab: {fileID: 197677485360569561, guid: b25a487d193f24049b6a791adf592b2e, type: 3}

View File

@ -97,7 +97,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
<Health>k__BackingField: 100 <Health>k__BackingField: 100
<movementSpeed>k__BackingField: 5 <movementSpeed>k__BackingField: 2
<rotSpeed>k__BackingField: 3 <rotSpeed>k__BackingField: 3
fov: 30 fov: 30
<attackRange>k__BackingField: 1.5 <attackRange>k__BackingField: 1.5

View File

@ -123,6 +123,128 @@ NavMeshSettings:
debug: debug:
m_Flags: 0 m_Flags: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1001 &343469760
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_RootOrder
value: 10
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.x
value: -10.64
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.y
value: 5.28
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_Name
value: Monster (4)
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
--- !u!1001 &378773076
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_RootOrder
value: 8
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.x
value: 11.100103
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.y
value: -3.5810318
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_Name
value: Monster (2)
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
--- !u!1001 &647315810 --- !u!1001 &647315810
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -193,6 +315,67 @@ Transform:
m_CorrespondingSourceObject: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3} m_CorrespondingSourceObject: {fileID: 1214567908930553594, guid: 3e0aae8cda56aef44af9598dc5471020, type: 3}
m_PrefabInstance: {fileID: 1942557562} m_PrefabInstance: {fileID: 1942557562}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1001 &804014058
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_RootOrder
value: 7
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.x
value: 11.39
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.y
value: 4.18
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_Name
value: Monster (1)
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
--- !u!1001 &992672924 --- !u!1001 &992672924
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -204,6 +387,10 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Gladiator value: Gladiator
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 197677485360569561, guid: b25a487d193f24049b6a791adf592b2e, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 197677485360569565, guid: b25a487d193f24049b6a791adf592b2e, type: 3} - target: {fileID: 197677485360569565, guid: b25a487d193f24049b6a791adf592b2e, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 1 value: 1
@ -259,8 +446,12 @@ PrefabInstance:
m_Modifications: m_Modifications:
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3} - target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_Enabled propertyPath: m_Enabled
value: 0 value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: -7596782781093632548, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: monsterPrefab
value:
objectReference: {fileID: 197677485360569561, guid: b25a487d193f24049b6a791adf592b2e, type: 3}
- target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3} - target: {fileID: 9196727425507610130, guid: 581322f036f3ff1448d4d2ec70f295a4, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 4 value: 4
@ -442,6 +633,67 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3} m_Script: {fileID: 11500000, guid: 81a29b049c6380f4abb3c18ed121efcd, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1001 &1622867918
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_RootOrder
value: 9
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.x
value: -11
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.y
value: -3.29
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995968, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_Name
value: Monster (3)
objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
--- !u!1001 &1826994674 --- !u!1001 &1826994674
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -497,6 +749,10 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: Monster value: Monster
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2399377275812995980, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 5f633c05dee3f4b4784f5702b2365f02, type: 3}
--- !u!1 &1836818727 --- !u!1 &1836818727

View File

@ -7,7 +7,7 @@ public class AIEntity : Entity
{ {
[SerializeField] AIStats stats = null!; [SerializeField] AIStats stats = null!;
BaseState currentState = null!; BaseState currentState = null!;
public string enemyName {get; protected set; } public string[] enemies {get; protected set; }
override protected void Awake(){ override protected void Awake(){
base.Awake(); base.Awake();
currentState = new FindTargetState(this); currentState = new FindTargetState(this);
@ -36,6 +36,17 @@ public class AIEntity : Entity
newState.EnterState(); newState.EnterState();
} }
//Looks into enemy name list to see if the other is targetable
virtual protected bool IsTargetable(Entity other){
foreach (string name in enemies){
if(other.entityName == name && other.IsAlive()){
return true;
}
}
return false;
}
abstract class BaseStateAI : BaseState{ abstract class BaseStateAI : BaseState{
protected AIEntity entity; protected AIEntity entity;
public BaseStateAI(AIEntity entity){ public BaseStateAI(AIEntity entity){
@ -66,11 +77,15 @@ public class AIEntity : Entity
public override BaseState? FixedUpdateState(){ public override BaseState? FixedUpdateState(){
Transform target = entity.GetTarget(); Transform target = entity.GetTarget();
entity.direction = Vector3.RotateTowards(entity.direction, (target.position - entity.transform.position), entity.rotSpeed*Time.fixedDeltaTime, 0.0f); entity.direction = Vector3.RotateTowards(entity.direction, (target.position - entity.transform.position), entity.rotSpeed*Time.fixedDeltaTime, 0.0f);
if(entity.IsTargetable(entity.GetTarget().GetComponent<Entity>())){
if(!entity.IsInAttackRange()){ if(!entity.IsInAttackRange()){
entity.rb.MovePosition(entity.transform.position + entity.direction * entity.movementSpeed * Time.fixedDeltaTime); entity.rb.MovePosition(entity.transform.position + entity.direction * entity.movementSpeed * Time.fixedDeltaTime);
}else{ }else{
return new AttackState(entity); return new AttackState(entity);
} }
}else{
return new FindTargetState(entity);
}
return null; return null;
} }
} }
@ -89,7 +104,7 @@ public class AIEntity : Entity
float lastDist = float.MaxValue; float lastDist = float.MaxValue;
Entity chosenEntity = null!; Entity chosenEntity = null!;
foreach (Entity other in entities){// Find the closest entity foreach (Entity other in entities){// Find the closest entity
if(other.name == entity.enemyName && other.IsAlive()){ if(entity.IsTargetable(other)){
float distance = Vector2.Distance(other.transform.position, entity.transform.position); float distance = Vector2.Distance(other.transform.position, entity.transform.position);
if(distance < lastDist){ if(distance < lastDist){
lastDist = distance; lastDist = distance;

View File

@ -6,7 +6,7 @@ public class Arena : MonoBehaviour {
//TODO probably add initial direction too //TODO probably add initial direction too
[SerializeField] Vector3[] spawners = null!; [SerializeField] Vector3[] spawners = null!;
[SerializeField] ArenaStats stats = null!; [SerializeField] ArenaStats stats = null!;
[SerializeField] GameObject monsterPrefab = null!; [SerializeField] GameObject entityPrefab = null!;
SafeZone safeZone = null!; SafeZone safeZone = null!;
@ -15,9 +15,9 @@ public class Arena : MonoBehaviour {
void Start() => StartCoroutine(SpawnEnemies()); void Start() => StartCoroutine(SpawnEnemies());
void SpawnEnemy(int spawnerIndex) { void SpawnEnemy(int spawnerIndex) {
var monster = Instantiate(monsterPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Monster>(); var entity = Instantiate(entityPrefab, spawners[spawnerIndex], Quaternion.identity).GetComponent<Entity>();
//TODO Replace hardcoded target with entity discovery //TODO Replace hardcoded target with entity discovery
monster.SetTarget(FindObjectOfType<PlayerMovement>().transform); entity.SetTarget(FindObjectOfType<PlayerMovement>().transform);
} }
IEnumerator SpawnEnemies() { IEnumerator SpawnEnemies() {

View File

@ -9,7 +9,27 @@ public class Gladiator : AIEntity
{ {
base.Start(); base.Start();
base.entityName = "Gladiator"; base.entityName = "Gladiator";
base.enemyName = "Monster"; base.enemies = new string[]{"Monster", "Vampire"};
}
override protected bool IsTargetable(Entity other){
foreach (string name in enemies){
if(other.entityName == name && other.IsAlive()){
//If it is the vampire: check if it is in safezone
if(other.entityName == "Vampire"){
VampireEntity vampireEntity = other.GetComponent<VampireEntity>();
if(vampireEntity is null){
return false;
}
if(vampireEntity.IsInSafeZone()){
return false;
}
}
return true;
}
}
return false;
} }
} }

View File

@ -9,7 +9,7 @@ public class Monster : AIEntity
{ {
base.Start(); base.Start();
base.entityName = "Monster"; base.entityName = "Monster";
base.enemyName = "Gladiator"; base.enemies = new string[]{"Gladiator"};
} }
} }

View File

@ -85,6 +85,13 @@ public class PlayerMovement : MonoBehaviour {
rb.isKinematic = !enabled; rb.isKinematic = !enabled;
} }
public bool IsInSafeZone(){
if(safeZone is null){
return false;
}
return safeZone.IsInSafeZone;
}
abstract class BaseStatePlayerMovement : BaseState{ abstract class BaseStatePlayerMovement : BaseState{
protected PlayerMovement playerMovement; protected PlayerMovement playerMovement;
public BaseStatePlayerMovement(PlayerMovement playerMovement){ public BaseStatePlayerMovement(PlayerMovement playerMovement){

View File

@ -5,10 +5,12 @@ using UnityEngine;
public class VampireEntity : Entity { public class VampireEntity : Entity {
[SerializeField] HealthBar healthBar; [SerializeField] HealthBar healthBar;
float initialHealth; float initialHealth;
PlayerMovement playerMovement;
protected override void Start() { protected override void Start() {
base.Start(); base.Start();
base.entityName = "Vampire"; base.entityName = "Vampire";
playerMovement = GetComponent<PlayerMovement>();
initialHealth = Health; initialHealth = Health;
} }
@ -17,4 +19,11 @@ public class VampireEntity : Entity {
base.TakeDamage(amount); base.TakeDamage(amount);
healthBar.SetHealthFraction(Health / initialHealth); healthBar.SetHealthFraction(Health / initialHealth);
} }
public bool IsInSafeZone(){
if(playerMovement is null){
return false;
}
return playerMovement.IsInSafeZone();
}
} }