This week's work:
The specific implementation of the child node of the Boss
and part of the conversion function
Since it is converted into a probability model, it is better to set it cautiously
The second is to find available resources for testing scripts.
/********************************************The following are child nodes*** ****************************/ //Intercept frame number update, set by the system public static void FSM_Test_Recorder(AIEntity pEntity){ pEntity.GetComponent <AIState> () .LastEntityData.AIPos = pEntity.AIPos; pEntity.GetComponent<AIState> ().LastEntityData.PlayerPos = pEntity.PlayerPos; pEntity.GetComponent<AIState> ().LastEntityData.PlayerEntity.GetComponent<HPComponent> ().tempHP = pEntity.PlayerEntity.GetComponent<HPComponent> ().tempHP; pEntity.GetComponent<AIState> ().LastEntityData.PlayerEntity.GetComponent<HPComponent> ().tempHurt = pEntity.PlayerEntity.GetComponent<HPComponent> ().tempHurt; } //Patrol can clear the exhaustion value and restore the blood volume to a large extent at this time (note that the exhaustion has not been written yet) public static void FSM_Walk(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().tempRoundPoint== Vector3.zero) { Vector2 trandom = Random.insideUnitCircle; pEntity.GetComponent<myBossAI> ().tempRoundPoint = pEntity.GetComponent<myBossAI> ().RoundCenter+(new Vector3(trandom.x,0,trandom.y))*pEntity.GetComponent<myBossAI>().RoundSize; } //If the acquisition distance is too close (may be stuck) while(Vector3.Distance(pEntity.GetComponent<myBossAI>().tempRoundPoint,pEntity.AIPos)<1.0f){ //Retrieve a 2D coordinate Vector2 trandom = Random.insideUnitCircle; pEntity.GetComponent<myBossAI> ().tempRoundPoint = pEntity.GetComponent<myBossAI> ().RoundCenter+(new Vector3(trandom.x,0,trandom.y))*pEntity.GetComponent<myAI>().RoundSize; } // Update the direction after getting it pEntity.GetComponent <AIMove> () .mDirection = (pEntity.GetComponent <myBossAI> () .tempRoundPoint-pEntity.AIPos) .normalized; pEntity.GetComponent <AIMove> () .mVelocity = pEntity.GetComponent <myBossAI> () .mWalkVelocity; pEntity.GetComponent<AIMove> ().mMoveFunc = MoveFunc.Complex;//I don't know what this is for, I have to ask //The code about fatigue is not written ***************************************** ************************ // only write to increase fatigue pEntity.GetComponent<myBossAI>().tired+=pEntity.GetComponent<myBossAI>().walkTiredValue; } // chase the enemy public static void FSM_Trace(AIEntity pEntity){ //If you find it, it will be troublesome to walk. In fact, it is to set a direction, speed, and movement method, as well as the current fatigue value. //AImove is basic //When chasing is when you see the player, you can get the player's position with PlyaerPos in pEntity pEntity.GetComponent <AIMove> () .mDirection = (pEntity.PlayerPos-pEntity.AIPos) .normalized; pEntity.GetComponent <AIMove> () .mVelocity = pEntity.GetComponent <myBossAI> () .mTraceVelocity; pEntity.GetComponent<AIMove> ().mMoveFunc = MoveFunc.Complex; pEntity.GetComponent<myBossAI> ().tired += pEntity.GetComponent<myBossAI> ().traceTiredValue; } // escape public static void FSM_RunAway(AIEntity pEntity){ //Run in the opposite direction of the player, while running towards the avoidance point, which is an array of a bunch of positions //Player in opposite direction Vector3 playerDir=(pEntity.AIPos-pEntity.PlayerPos).normalized; float playerDistance = Vector3.Distance (pEntity.AIPos, pEntity.PlayerPos);//Calculate the distance between AI and player int count = 0; while (count <= 7) { int index = Random.Range (0, pEntity.GetComponent<myBossAI> ().HiddenPoint.Length); count++; // hidden point direction Vector3 HiddenDir = (pEntity.GetComponent<myBossAI> ().HiddenPoint [index].position - pEntity.AIPos).normalized; //Calculate the hidden point and the player's position float HiddenDistance = Vector3.Distance(pEntity.GetComponent<myBossAI>().HiddenPoint[index].position,pEntity.PlayerPos); if(HiddenDistance-playerDistance>1.0f&&Vector3.Dot(playerDir,HiddenDir)>=0.1f){ pEntity.GetComponent<AIMove> ().mDirection = HiddenDir; break; } } if (count > 7) { //Indicate that a better hidden point position has not been found pEntity.GetComponent<AIMove>().mDirection=playerDir; } pEntity.GetComponent <AIMove> () .mVelocity = pEntity.GetComponent <myBossAI> () .mTraceVelocity + 1; pEntity.GetComponent<AIMove> ().mMoveFunc = MoveFunc.Complex; pEntity.GetComponent<myBossAI> ().tired += pEntity.GetComponent<myBossAI> ().runawayTiredValue; } //call minion public static void FSM_CallOthers(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().CallOtherRate > 0) { pEntity.GetComponent<myBossAI> ().CallOtherRate -= Time.deltaTime; } else { pEntity.GetComponent<myBossAI> ().CallOtherRate = 3.0f; Debug.Log ("Call Other"); } } public static void FSM_CallOthersExit(AIEntity pEntity){ pEntity.GetComponent<myBossAI> ().CallOtherRate = 3.0f; } /************Attack related*********************************** **************************************************** *****/ //There are three kinds of Special Attack, and there are two kinds of Normal Attack, namely (remote) and melee public static void FSM_SpecialAttack1(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().groundAttackRate > 0.0f) { pEntity.GetComponent<myBossAI> ().groundAttackRate -= Time.deltaTime; } else { // can attack pEntity.GetComponent<myBossAI>().groundAttackRate=pEntity.GetComponent<myBossAI>().groundAttackRateValue; //Change tempHP, how to get the player's HP and then send it back? pEntity.GetComponent<myBossAI>().tempHP-=10; pEntity.GetComponent<BaseAIComponent> ().mAIRT.transform.forward = (pEntity.PlayerPos - pEntity.AIPos).normalized; pEntity.GetComponent <myBossAI> () .fire_Timer + = Time.deltaTime; pEntity.GetComponent<myBossAI> ().tired += 10; } } public static void FSM_SpecialAttack_Exit(AIEntity pEntity){ pEntity.GetComponent<myBossAI> ().fire_Timer = 0.0f; pEntity.GetComponent<myBossAI> ().groundAttackRate = pEntity.GetComponent<myBossAI> ().groundAttackRateValue; } //Range attack 1: put fire public static void FSM_FarAttack1(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().FarAttackRate > 0) { pEntity.GetComponent<myBossAI> ().FarAttackRate -= Time.deltaTime; } else { pEntity.GetComponent<myBossAI> ().FarAttackRate = 0.5f; Shoot (pEntity); } } //Range attack 2: put special effects public static void FSM_FarAttack2(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().FarMagicRate > 0) { } else { if (pEntity.GetComponent<myBossAI> ().MagicValue >=10.0f) { pEntity.GetComponent<myBossAI> ().FarMagicRate = 2.0f; pEntity.GetComponent<myBossAI> ().MagicValue -= 10.0f; } } } // end of attack public static void FSM_AttackExit(AIEntity pEntity){ } /**********************************************************************************************************************/ //Various conversion functions //Any state is converted to escape public static float Transfer_AnyToRunaway(AIEntity pEntity){ if (pEntity.GetComponent<myBossAI> ().tempHP < pEntity.GetComponent<myBossAI> ().HPValue) { float rate = (0.5f * pEntity.GetComponent<myBossAI> ().HPValue - pEntity.GetComponent<myBossAI> ().tempHP) / (0.5f * pEntity.GetComponent<myBossAI> ().HPValue); if (pEntity.GetComponent<AIEmotion> ().GetTempEmotion () == "Fear") rate *= 1.5f; return rate; } return 0.0f; } // Convert from walking to chasing public static float Transfer_WalkToTrace(AIEntity pEntity){ float dis = Vector3.Distance (pEntity.AIPos, pEntity.PlayerPos); // view direction float angle=Vector3.Dot((pEntity.PlayerPos-pEntity.AIPos).normalized,pEntity.GetComponent<AIMove>().mDirection); if (dis < 20.0f && angle >= 0.2) { //Change the possibility of pursuit based on tired value return (20 - dis) * 0.1 *( 1-pEntity.GetComponent<myBossAI> ().tired / 100) * pEntity.GetComponent<myBossAI> ().tempHP / pEntity.GetComponent<myBossAI> ().HPValue; } else return 0.0f; } // Convert from pursuit to attack
void Shoot(AIEntity pEn){ Ray myRay; RaycastHit myHit; pEn.GetComponent<myBossAI> ().fire.Stop (); pEn.GetComponent<myBossAI> ().fire.Play (); myRay.origin = pEn.AIPos; myRay.direction = pEn.GetComponent<AIMove> ().mDirection; if (Physics.Raycast (myRay, out myHit, 100, pEn.GetComponent<myBossAI> ().ShootableMask)) { //Because I don't know where to find the player's hp //First replace it with the Enermy class written by yourself EnemyDamage eDamage=myHit.collider.GetComponent<EnermyDamage>(); if (eDamage != null) { eDamage.Damage (10.0f); } } }
I found that my attack was not written rigorously, and I needed to continue to revise it.
In addition, the probability conversion of the diversity of ground attacks also needs to consider a reasonable plan.