slime wandering

This commit is contained in:
2022-04-25 16:34:38 +03:00
parent 34035c5b3d
commit 0d597af869
16 changed files with 503 additions and 259 deletions

View File

@@ -257,28 +257,6 @@ AnimatorController:
m_IKPass: 0
m_SyncedLayerAffectsTiming: 0
m_Controller: {fileID: 9100000}
--- !u!1101 &1101015791221655006
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102615628393760256}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 4
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101032411631014566
AnimatorStateTransition:
m_ObjectHideFlags: 1
@@ -323,28 +301,6 @@ AnimatorStateTransition:
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101110224531333392
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102508070621265122}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 4
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101133745856325530
AnimatorStateTransition:
m_ObjectHideFlags: 1
@@ -736,8 +692,7 @@ AnimatorState:
m_Name: Attack02
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 1101110224531333392}
m_Transitions: []
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
@@ -818,7 +773,7 @@ AnimatorState:
m_Speed: 1
m_CycleOffset: 0
m_Transitions:
- {fileID: 1101015791221655006}
- {fileID: 4009614032068998235}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
@@ -846,6 +801,7 @@ AnimatorState:
m_CycleOffset: 0
m_Transitions:
- {fileID: -9125041204588145995}
- {fileID: 7867290979486804741}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
@@ -1045,7 +1001,7 @@ AnimatorStateMachine:
m_Position: {x: 650, y: 280, z: 0}
- serializedVersion: 1
m_State: {fileID: 1102508070621265122}
m_Position: {x: 900, y: 30, z: 0}
m_Position: {x: 430, y: 20, z: 0}
- serializedVersion: 1
m_State: {fileID: 1102615628393760256}
m_Position: {x: 900, y: 120, z: 0}
@@ -1101,6 +1057,50 @@ AnimatorStateMachine:
m_ExitPosition: {x: 90, y: 510, z: 0}
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
m_DefaultState: {fileID: 1102546605246812244}
--- !u!1101 &4009614032068998235
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102546605246812244}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &7867290979486804741
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions: []
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102508070621265122}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.85
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1102 &8194647877007136643
AnimatorState:
serializedVersion: 6

View File

@@ -361,6 +361,7 @@ GameObject:
- component: {fileID: 8377414142725635096}
- component: {fileID: 9217037737240071080}
- component: {fileID: 979664278525990523}
- component: {fileID: 7068053744138324038}
m_Layer: 0
m_Name: BossSlime
m_TagString: BossSlime
@@ -431,8 +432,21 @@ Rigidbody:
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_Constraints: 112
m_CollisionDetection: 0
--- !u!135 &7068053744138324038
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8437010424349675124}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.6
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!1 &8437097380876049792
GameObject:
m_ObjectHideFlags: 0

View File

@@ -361,6 +361,7 @@ GameObject:
- component: {fileID: 8377414142725635096}
- component: {fileID: 9217037737240071080}
- component: {fileID: 979664278525990523}
- component: {fileID: 6363954507592996496}
m_Layer: 0
m_Name: SlimePBR
m_TagString: Slime
@@ -378,7 +379,7 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 1.3906298, y: 0.00000023841858, z: -0.086076975}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 8439521210071859164}
- {fileID: 8439236181366124486}
@@ -431,8 +432,21 @@ Rigidbody:
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_Constraints: 112
m_CollisionDetection: 0
--- !u!135 &6363954507592996496
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8437010424349675124}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.6
m_Center: {x: 0, y: 0.5, z: 0}
--- !u!1 &8437097380876049792
GameObject:
m_ObjectHideFlags: 0

View File

@@ -11,6 +11,14 @@ public class SlimeAI : MonoBehaviour
GameObject player;
int HP;
public float moveSpeed = 3f;
public float rotSpeed = 100f;
private bool isWandering = false;
private bool isRotatingLeft = false;
private bool isRotatingRight = false;
private bool isWalking = false;
//[SerializeField]
//private UnityEvent onAttack;
@@ -33,7 +41,7 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInVisionRange", true);
Rotate();
}
else if (playerDistance < 5) //Chase
else if (playerDistance < 10) //Chase
{
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", true);
@@ -41,7 +49,7 @@ public class SlimeAI : MonoBehaviour
Rotate();
Move();
}
else if (playerDistance < 8) //Stare
else if (playerDistance < 18) //Stare
{
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", false);
@@ -53,6 +61,23 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInAttackRange", false);
animator.SetBool("EnemyInAggroRange", false);
animator.SetBool("EnemyInVisionRange", false);
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;
}
}
if (HP <= 0)
{
@@ -63,6 +88,8 @@ public class SlimeAI : MonoBehaviour
print("asd");
Destroy(this.gameObject);
}
}
void Rotate()
{
@@ -81,4 +108,35 @@ public class SlimeAI : MonoBehaviour
{
HP -= dmg;
}
IEnumerator Wander()
{
int rotTime = Random.Range(1, 3);
int rotateWait = Random.Range(1, 4);
int rotateLorR = Random.Range(1, 2);
int walkWait = Random.Range(1, 5);
int walkTime = Random.Range(1, 6);
isWandering = true;
yield return new WaitForSeconds(walkWait);
isWalking = true;
yield return new WaitForSeconds(walkTime);
isWalking = false;
yield return new WaitForSeconds(rotateWait);
if (rotateLorR == 1)
{
isRotatingRight = true;
yield return new WaitForSeconds(rotTime);
isRotatingRight = false;
}
if (rotateLorR == 2)
{
isRotatingLeft = true;
yield return new WaitForSeconds(rotTime);
isRotatingLeft = false;
}
isWandering = false;
}
}