wandering implemented

This commit is contained in:
2022-04-25 17:41:22 +03:00
parent fd683b4580
commit a748b342a8
18 changed files with 325 additions and 233 deletions

View File

@@ -231,19 +231,25 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: EnemyInAggroRange
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: EnemyInAttackRange
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Wandering
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
@@ -1037,7 +1043,7 @@ AnimatorStateMachine:
m_Position: {x: 670, y: 550, z: 0}
- serializedVersion: 1
m_State: {fileID: 1102835054974116572}
m_Position: {x: 280, y: 510, z: 0}
m_Position: {x: 280, y: 500, z: 0}
- serializedVersion: 1
m_State: {fileID: 8194647877007136643}
m_Position: {x: 300, y: 220, z: 0}
@@ -1064,7 +1070,10 @@ AnimatorStateTransition:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: Wandering
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102546605246812244}
m_Solo: 0
@@ -1086,7 +1095,10 @@ AnimatorStateTransition:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: Wandering
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102508070621265122}
m_Solo: 0

View File

@@ -362,6 +362,7 @@ GameObject:
- component: {fileID: 9217037737240071080}
- component: {fileID: 979664278525990523}
- component: {fileID: 7068053744138324038}
- component: {fileID: -8446248727669723812}
m_Layer: 0
m_Name: BossSlime
m_TagString: BossSlime
@@ -418,6 +419,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2a6f17609e4d7c441b8f85c0f90c1a13, type: 3}
m_Name:
m_EditorClassIdentifier:
moveSpeed: 1
rotSpeed: 50
--- !u!54 &979664278525990523
Rigidbody:
m_ObjectHideFlags: 0
@@ -447,6 +450,28 @@ SphereCollider:
serializedVersion: 2
m_Radius: 0.6
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!195 &-8446248727669723812
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8437010424349675124}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 2
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!1 &8437097380876049792
GameObject:
m_ObjectHideFlags: 0

View File

@@ -362,6 +362,7 @@ GameObject:
- component: {fileID: 9217037737240071080}
- component: {fileID: 979664278525990523}
- component: {fileID: 6363954507592996496}
- component: {fileID: 8521358267821330725}
m_Layer: 0
m_Name: SlimePBR
m_TagString: Slime
@@ -418,6 +419,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 2a6f17609e4d7c441b8f85c0f90c1a13, type: 3}
m_Name:
m_EditorClassIdentifier:
moveSpeed: 1
rotSpeed: 100
--- !u!54 &979664278525990523
Rigidbody:
m_ObjectHideFlags: 0
@@ -447,6 +450,28 @@ SphereCollider:
serializedVersion: 2
m_Radius: 0.6
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!195 &8521358267821330725
NavMeshAgent:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8437010424349675124}
m_Enabled: 1
m_AgentTypeID: 0
m_Radius: 0.5
m_Speed: 3.5
m_Acceleration: 8
avoidancePriority: 50
m_AngularSpeed: 120
m_StoppingDistance: 0
m_AutoTraverseOffMeshLink: 1
m_AutoBraking: 1
m_AutoRepath: 1
m_Height: 1
m_BaseOffset: 0
m_WalkableMask: 4294967295
m_ObstacleAvoidanceType: 4
--- !u!1 &8437097380876049792
GameObject:
m_ObjectHideFlags: 0

View File

@@ -11,7 +11,7 @@ public class SlimeAI : MonoBehaviour
GameObject player;
int HP;
public float moveSpeed = 3f;
public float moveSpeed = 4f;
public float rotSpeed = 100f;
private bool isWandering = false;
@@ -28,6 +28,7 @@ public class SlimeAI : MonoBehaviour
animator = GetComponent<Animator>();
player = GameObject.FindWithTag("Player");
HP = 10;
}
// Update is called once per frame
@@ -36,6 +37,7 @@ public class SlimeAI : MonoBehaviour
playerDistance = Vector3.Distance(player.transform.position, transform.position);
if (playerDistance < 1.5) //Attack
{
animator.SetBool("Wandering", false);
animator.SetBool("EnemyInAttackRange", true);
animator.SetBool("EnemyInAggroRange", true);
animator.SetBool("EnemyInVisionRange", true);
@@ -43,6 +45,7 @@ public class SlimeAI : MonoBehaviour
}
else if (playerDistance < 10) //Chase
{
animator.SetBool("Wandering", false);
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", true);
animator.SetBool("EnemyInVisionRange", true);
@@ -51,33 +54,42 @@ public class SlimeAI : MonoBehaviour
}
else if (playerDistance < 18) //Stare
{
animator.SetBool("Wandering", false);
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", false);
animator.SetBool("EnemyInVisionRange", true);
Rotate();
StopCoroutine("Wandering");
}
else //Idle
else
{
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", false);
animator.SetBool("EnemyInVisionRange", false);
}
if (!isWandering)
{
//Idle
StartCoroutine("Wander");
if (isRotatingRight == true)
{
gameObject.GetComponent<Animator>().Play("IdleNormal");
transform.Rotate(transform.up * Time.deltaTime * rotSpeed);
}
if (isRotatingLeft == true)
{
gameObject.GetComponent<Animator>().Play("IdleNormal");
transform.Rotate(transform.up * Time.deltaTime * -rotSpeed);
}
if (isWalking == true)
{
gameObject.GetComponent<Animator>().Play("WalkFWD");
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
}
Debug.Log(isWandering);
Debug.Log(isRotatingLeft);
Debug.Log(isRotatingRight);
if (isRotatingRight == true)
{
animator.SetBool("Wandering", false);
transform.Rotate(transform.up * Time.deltaTime * rotSpeed);
}
if (isRotatingLeft == true)
{
animator.SetBool("Wandering", false);
transform.Rotate(transform.up * Time.deltaTime * -rotSpeed);
}
if (isWalking == true)
{
animator.SetBool("Wandering", true);
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
if (HP <= 0)
{
@@ -112,10 +124,10 @@ public class SlimeAI : MonoBehaviour
IEnumerator Wander()
{
int rotTime = Random.Range(1, 3);
int rotateWait = Random.Range(1, 4);
int rotateWait = Random.Range(1, 5);
int rotateLorR = Random.Range(1, 2);
int walkWait = Random.Range(1, 5);
int walkTime = Random.Range(1, 6);
int walkTime = Random.Range(1, 20);
isWandering = true;

View File

@@ -29,7 +29,7 @@ public class SlimeSpawner : MonoBehaviour
{
float slimeRandom = Random.Range(0, slimeTypes.Count);
float spawnRandom = Random.Range(0, spawnLocations.Count);
Instantiate(slimeTypes[Mathf.RoundToInt(slimeRandom)], spawnLocations[Mathf.RoundToInt(spawnRandom)].position, Quaternion.identity);
Instantiate(slimeTypes[Mathf.RoundToInt(slimeRandom)], spawnLocations[Mathf.RoundToInt(spawnRandom)].position, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
}
}