public override void Update(UEntity uEntity) { base.Update(uEntity); Vector3 pos = uEntity.GetComponent <ZoologyComponent> ().mPosition; float maxRiaus = Mathf.Max(uEntity.GetComponent <ZoologyComponent>().mSize.x, uEntity.GetComponent <ZoologyComponent>().mSize.y); SimpleAI[] tSimpleAIs = SimpleAISetSingleton.getInstance().GetComponent <SimpleAISet> ().FindAIsWithRiaus(pos, maxRiaus, 1 << LayerMask.NameToLayer("Default"), "AI"); List <GAPopulation> tList = new List <GAPopulation> (); for (int i = 0; i < tSimpleAIs.Length; i++) { if (!tList.Contains(GAPopulation.allDic[tSimpleAIs[i].mType])) { tList.Add(GAPopulation.allDic[tSimpleAIs[i].mType]); } } float avgRate = 0.0f; foreach (var v in tList) { avgRate += v.lifeRate; } avgRate /= tList.Count; if (avgRate < 0.2f) { uEntity.GetComponent <ZoologyComponent> ().mState = false; } else { uEntity.GetComponent <ZoologyComponent> ().mState = true; } }
public override void Update(UEntity uEntity) { int lod = uEntity.GetComponent <LODComponent> ().mLOD; Animator tAnimator = uEntity.GetComponent <AIAnimation> ().mAnimator; if (tAnimator == null) { return; } // get lod value if (lod > ((float)LODComponent.maxLOD) / 3.0f * 2.0f) { tAnimator.enabled = false; } else { tAnimator.enabled = true; } /* * if (lod > (LODComponent.maxLOD)/2.0f) * return; */ AnimationPlay tAnim = uEntity.GetComponent <AIAnimation> ().Get(uEntity.GetComponent <AIAnimation>().mtempAnim); // update animation tAnim(tAnimator); }
/* * @param uEntity: Entity having LODComponent in temp World * Compute LOD for this AI */ public override void Update(UEntity uEntity) { base.Update(uEntity); if (lodDistance.Length == 0) { return; } if (mPlayer == null) { return; } if (!uEntity.GetComponent <LODComponent> ().isUse) { uEntity.GetComponent <LODComponent> ().mLOD = 1; return; } GameObject tObject = getObjectByEntity(uEntity); // Compute by Distance with Player(Camera) float dis = Vector3.Distance(mPlayer.transform.position, tObject.transform.position); for (int i = 0; i < lodDistance.Length; i++) { if (dis < lodDistance [i]) { uEntity.GetComponent <LODComponent> ().mLOD = i + 1; return; } } uEntity.GetComponent <LODComponent> ().mLOD = lodDistance.Length + 1; }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <LODComponent> () != null) { int lod = uEntity.GetComponent <LODComponent> ().mLOD; if (lod > LODComponent.maxLOD / 2) { return; } } string tWhere = uEntity.GetComponent <InfluenceMapTrigger> ().mWhere; InfluenceMap tInfluenceMap = InfluenceMap.getInstance(); int index = tInfluenceMap.mDictionary [tWhere]; bool isStatic = tInfluenceMap.mDicStatic [index]; if (!isStatic) { Vector3 position; Vector3 size; if (uEntity.GetComponent <InfluenceMapTrigger> ().mGameObject.GetComponent <MeshRenderer> ()) { position = uEntity.GetComponent <InfluenceMapTrigger>().mGameObject.GetComponent <MeshRenderer> ().bounds.center; size = uEntity.GetComponent <InfluenceMapTrigger>().mGameObject.GetComponent <MeshRenderer> ().bounds.size; } else { position = uEntity.GetComponent <InfluenceMapTrigger>().mGameObject.GetComponentInChildren <MeshRenderer> ().bounds.center; size = uEntity.GetComponent <InfluenceMapTrigger>().mGameObject.GetComponentInChildren <MeshRenderer> ().bounds.size; } Vector2 LeftDown = new Vector2(position.x - size.x / 2, position.z - size.z / 2); Vector2 tileLeftDown = InfluenceMap.getInstance().getTilefromPosition(LeftDown); Vector2 RightUp = new Vector2(position.x + size.x / 2, position.z + size.z / 2); Vector2 tileRightUp = InfluenceMap.getInstance().getTilefromPosition(RightUp); float IMdata = uEntity.GetComponent <InfluenceMapTrigger> ().mIMComputer(uEntity); float maxInfluence = uEntity.GetComponent <InfluenceMapTrigger> ().maxInfluence; for (int i = (int)tileLeftDown.x; i <= tileRightUp.x; i++) { for (int j = (int)tileLeftDown.y; j <= tileRightUp.y; j++) { Vector2 tTile = new Vector2(i, j); fillTile(tTile, index, IMdata, maxInfluence); } } } }
public override void Update(UEntity uEntity) { base.Update(uEntity); while (uEntity.GetComponent <HurtManager> ().mHurtEventList.Count != 0) { HurtEvent the = uEntity.GetComponent <HurtManager> ().mHurtEventList.Dequeue(); the.fir.GetComponent <HPComponent> ().tempHurt = the.hurtnumber; the.sec.GetComponent <HPComponent> ().tempHP -= the.hurtnumber; } }
public override void Update(UEntity uEntity) { if (uEntity.GetComponent <DestroyComponent> ().DestroyTime > 0) { uEntity.GetComponent <DestroyComponent> ().DestroyTime -= Time.deltaTime; } else { uEntity.Release(); } }
/* * @param uEntity: Entity * * @return: the AI GameObject with this Entity * */ private GameObject getObjectByEntity(UEntity uEntity) { if (uEntity.GetComponent <BaseAIComponent> () != null) { return(uEntity.GetComponent <BaseAIComponent> ().mAIRT); } else { return(((SimpleAI)uEntity).mAIRT); } }
public override void Update(UEntity uEntity) { base.Update(uEntity); float headDamage = uEntity.GetComponent <bombAI> ().RigHead.GetComponent <enemyHit> ().damage; uEntity.GetComponent <bombAI> ().RigHead.GetComponent <enemyHit> ().damage = 0.0f; if (headDamage > 0.0f) { uEntity.GetComponent <getPlayer> ().engage = true; } uEntity.GetComponent <bombAI> ().HPNow -= headDamage; }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (((AIEntity)uEntity).mPlayer != null) { ((AIEntity)uEntity).PlayerPos = ((AIEntity)uEntity).mPlayer.transform.position; } ((AIEntity)uEntity).AIPos = uEntity.GetComponent <BaseAIComponent> ().mAIRT.transform.position; GameObject tObject = uEntity.GetComponent <BaseAIComponent> ().mAIRT; uEntity.GetComponent <HPComponent> ().tempHurt = 0; }
public override void Update(UEntity uEntity) { base.Update(uEntity); int lod = uEntity.GetComponent <LODComponent>().mLOD; if (lod > LODComponent.maxLOD / 2) { return; } if (uEntity.GetComponent <AIEmotion> ().timer < 1.0f) { uEntity.GetComponent <AIEmotion> ().timer += Time.deltaTime; return; } // update emotion uEntity.GetComponent <AIEmotion> ().timer = 0.0f; for (int i = 0; i < uEntity.GetComponent <AIEmotion> ().mEmotion.Count; i++) { EmotionExecuter tEmotionExecuter = uEntity.GetComponent <AIEmotion> ().mEmotion[i].mEmotionExecuter; float tactive = tEmotionExecuter((AIEntity)(uEntity)); if (Random.Range(0.0f, 1.0f) < tactive) { uEntity.GetComponent <AIEmotion> ().mtempID = uEntity.GetComponent <AIEmotion> ().mEmotion[i].id; break; } } }
public override void Update(UEntity uEntity) { // Debug.Log ("UpdateAntSystem"); base.Update(uEntity); List <AntPopulation> tList = uEntity.GetComponent <AntPopulationComponent> ().mAntPopulationSet; for (int i = 0; i < AntPopulation.mNowListCount; i++) { if (tList [i].isStartFind) { if (tList[i].shouldWhat == 0) { InfluenceMap.getInstance().Show(3); } else if (tList[i].shouldWhat == 1) { InfluenceMap.getInstance().Show(4); } UpdateAntPopulation(tList [i]); } } }
public static float round2runaway(UEntity uEntity) { GameObject aiRT = uEntity.GetComponent <BaseAIComponent> ().mAIRT; TestCollision tc = null; if (aiRT.GetComponent <TestCollision> () != null) { tc = aiRT.GetComponent <TestCollision> (); } else if (aiRT.GetComponentInChildren <TestCollision> () != null) { tc = aiRT.GetComponent <TestCollision> (); } if (tc.TriggerObject == null) { return(0.0f); } if (tc.isTriggerEnter == true && tc.TriggerObject.name == "Boom") { Debug.Log(tc.TriggerObject.name); return(1.0f); } else { return(0.0f); } }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (((AIEntity)uEntity).mDissloveTimer > 0.0f) { ((AIEntity)uEntity).mDissloveTimer -= Time.deltaTime; } if (((AIEntity)uEntity).isGrouping) { uEntity.GetComponent <AIState> ().isEnable = false; uEntity.GetComponent <AIGroupState> ().isEnable = true; uEntity.GetComponent <AIStrategy> ().isEnable = false; } else { uEntity.GetComponent <AIState> ().isEnable = true; uEntity.GetComponent <AIStrategy> ().isEnable = true; if (uEntity.GetComponent <AIGroupState>() != null) { uEntity.GetComponent <AIGroupState> ().isEnable = false; } } }
// 要注意到之后的逻辑,在节点中,只靠是否insight来进行判断的 public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <showAll> ().singleTest) { uEntity.GetComponent <showAll> ().mAction.GetComponent <Text> ().text = "Action: " + uEntity.GetComponent <AIStrategy> ().mTempName; uEntity.GetComponent <showAll> ().mNode.GetComponent <Text> ().text = "Node: " + uEntity.GetComponent <AIState> ().mTempName; uEntity.GetComponent <showAll> ().mEmotion.GetComponent <Text> ().text = "Emotion: " + uEntity.GetComponent <AIEmotion> ().mtempName; uEntity.GetComponent <showAll> ().mAnimation.GetComponent <Text> ().text = "Animation: " + uEntity.GetComponent <AIAnimation> ().mtempAnim; } }
public override void Update(UEntity uEntity) { if (uEntity.GetComponent <StateComponent> ().AttackState) { GameObject g = uEntity.GetComponent <RenderComponent> ().renderObject; UEntity tUEntity = new UEntity(); mWorld.registerEntity(tUEntity); tUEntity.mAllBitBunch.SetCount((int)mWorld.mComponentCount); MoveComponent mc = new MoveComponent(); mc.dir = g.transform.forward; mc.velocity = uEntity.GetComponent <BattleComponent> ().Velocity; tUEntity.AddComponent <MoveComponent> (mc); GameObject g1 = GameObject.Instantiate(uEntity.GetComponent <BattleComponent> ().bullet, g.transform.position, Quaternion.identity); RenderComponent rc = new RenderComponent(); rc.renderObject = g1; DestroyComponent dc = new DestroyComponent(); dc.DestroyTime = 5.0f; tUEntity.AddComponent <RenderComponent> (rc); tUEntity.AddComponent <DestroyComponent> (dc); uEntity.GetComponent <StateComponent> ().AttackState = false; } }
public override void Update(UEntity uEntity) { base.Update(uEntity); List <SimpleAI> last = uEntity.GetComponent <SimpleAISet>().LastFrameRemove; foreach (var vAI in last) { uEntity.GetComponent <SimpleAISet> ().mSimpleAIList.Remove(vAI); uEntity.mWorld.deleteEntity(vAI); GameObject.Destroy(vAI.mAIRT); } last.Clear(); List <SimpleAI> tAIList = uEntity.GetComponent <SimpleAISet> ().mSimpleAIList; for (int i = 0; i < tAIList.Count; i++) { int lod = tAIList[i].GetComponent <LODComponent>().mLOD; if (lod > LODComponent.maxLOD / 2) { if (tAIList [i].mAIRT.GetComponent <Animator> () != null) { tAIList [i].mAIRT.GetComponent <Animator> ().enabled = false; } return; } else { if (tAIList [i].mAIRT.GetComponent <Animator> () != null) { tAIList [i].mAIRT.GetComponent <Animator> ().enabled = true; } } string code = tAIList [i].mSimpleAIStateJudger.DoJudge(tAIList[i]); tAIList [i].mSimpleAIRunner.DoRun(tAIList[i], code); } }
private GameObject getGameObjectFromEntity(UEntity pEntity) { BaseAIComponent bAI = pEntity.GetComponent <BaseAIComponent> (); if (bAI != null) { return(bAI.mAIRT); } else { return(((SimpleAI)pEntity).mAIRT); } }
/* * if a transfer,then you should capture the next 10 frame with feedback function * */ public override void Update(UEntity uEntity) { if (uEntity.GetComponent <AIState> ().mCaptureFrame != 0) { int tIndex = uEntity.GetComponent <AIState> ().mCaptureFrame - 1; float tLast = uEntity.GetComponent <AIState> ().mTempFeedbacker((AIEntity)uEntity.GetComponent <AIState>().LastEntityData, false); float tNow = uEntity.GetComponent <AIState> ().mTempFeedbacker((AIEntity)uEntity, true); uEntity.GetComponent <AIState> ().mframebuffer [tIndex] = Mathf.Abs(tLast) - Mathf.Abs(tNow); uEntity.GetComponent <AIState> ().mCaptureFrame--; if (uEntity.GetComponent <AIState> ().mCaptureFrame == 0) { uEntity.GetComponent <AIState> ().mFeedbackerState = true; } } }
// the some as AIState public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <AIStrategy> ().mFrameCaptureStart) { if (uEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter == 0) { uEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = false; return; } int tempID = uEntity.GetComponent <AIStrategy> ().LastID; StrategyFeedbacker tempFeedbacker = uEntity.GetComponent <AIStrategy> ().mStrategyFeedbacker [tempID]; float rate1 = tempFeedbacker((AIEntity)uEntity); float rate2 = tempFeedbacker(uEntity.GetComponent <AIState>().LastEntityData); uEntity.GetComponent <AIStrategy> ().bufferdata [10 - uEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter] = rate1 - rate2; } }
// the same as AIState public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter == 0) { float sum = 0.0f; for (int i = 0; i < 10; i++) { sum += uEntity.GetComponent <AIStrategy> ().bufferdata [i]; } sum /= 10.0f; uEntity.GetComponent <AIStrategy> ().mPower [uEntity.GetComponent <AIStrategy> ().LastID] += sum; uEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter = 10; uEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = false; } }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <trapComponent> ().trapNow == 1) { return; } if (uEntity.GetComponent <trapComponent> ().trapRate >= 0.0f) { uEntity.GetComponent <trapComponent> ().trapRate -= Time.deltaTime; } else { uEntity.GetComponent <trapComponent> ().trapCount--; uEntity.GetComponent <trapComponent> ().trapNow = 1; uEntity.GetComponent <trapComponent> ().trapRate = 10.0f; } }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (!uEntity.GetComponent <AIStrategy> ().isEnable) { return; } AIEntity pEntity = (AIEntity)uEntity; // get lod now int lod = uEntity.GetComponent <LODComponent> ().mLOD; // compute logic update velocity lod = lod * lod * lod; // update logic with lod if (pEntity.GetComponent <AIStrategy> ().timer <= 0.2f * lod) { pEntity.GetComponent <AIStrategy> ().timer += Time.deltaTime; return; } pEntity.GetComponent <AIStrategy> ().timer = 0.0f; // having cache ? if (pEntity.GetComponent <AIStrategy> ().IDBuffer != -1) { if (pEntity.GetComponent <AIStrategy> ().BufferFrame != 0) { pEntity.GetComponent <AIStrategy> ().BufferFrame--; } else { pEntity.GetComponent <AIStrategy> ().IDBuffer = -1; } return; } //the min value of the strategy action float minValue = 0.15f; // the max actionNode tActionNode1 = new actionNode(); tActionNode1.action = 0.0f; tActionNode1.mid = -1; // the second max actionNode tActionNode2 = new actionNode(); tActionNode2.action = 0.0f; tActionNode2.mid = -1; for (int i = 0; i < pEntity.GetComponent <AIStrategy> ().tempCount; i++) { float tempRate = pEntity.GetComponent <AIStrategy> ().mStrategyActioner [i](pEntity); tempRate *= pEntity.GetComponent <AIStrategy> ().mPower [i]; if (tempRate > tActionNode1.action) { tActionNode2.action = tActionNode1.action; tActionNode2.mid = tActionNode1.mid; tActionNode1.action = tempRate; tActionNode1.mid = i; } else if (tempRate > tActionNode2.action) { tActionNode2.action = tempRate; tActionNode2.mid = i; } } if (tActionNode1.action > minValue) { if (tActionNode1.mid == pEntity.GetComponent <AIStrategy> ().tempID) { return; } // transfer, so compute the last frame data if (pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter != 10) { float sum = 0.0f; for (int i = 0; i < 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter; i++) { sum += pEntity.GetComponent <AIStrategy> ().bufferdata [i]; } sum /= 10 - pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter; pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] += sum; if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] > 3.0f) { pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 3.0f; } if (pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] < 0.3f) { pEntity.GetComponent <AIStrategy> ().mPower [pEntity.GetComponent <AIStrategy> ().LastID] = 0.3f; } pEntity.GetComponent <AIStrategy> ().mFrameCaptureCounter = 10; } pEntity.GetComponent <AIStrategy> ().LastID = pEntity.GetComponent <AIStrategy> ().tempID; pEntity.GetComponent <AIStrategy> ().mFrameCaptureStart = true; for (int i = 0; i < pEntity.GetComponent <AIState> ().mtempCount; i++) { for (int j = 0; j < pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i].Count; j++) { PowerNode pnt = new PowerNode(); pnt.id = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].id; pnt.power = pEntity.GetComponent <AIState> ().mPowerEdge [i] [j].power; pEntity.GetComponent <AIStrategy> ().mAIState [pEntity.GetComponent <AIStrategy> ().tempID].mPowerEdge [i] [j] = pnt; } } // update Strategy pEntity.GetComponent <AIStrategy> ().mStrategyExit[pEntity.GetComponent <AIStrategy>().tempID](pEntity); pEntity.GetComponent <AIStrategy> ().SetEntry(tActionNode1.mid); pEntity.GetComponent <AIStrategy> ().mStrategyEnter[pEntity.GetComponent <AIStrategy>().tempID](pEntity); // update cache if (tActionNode1.action - tActionNode2.action > 0.3f) { pEntity.GetComponent <AIStrategy> ().IDBuffer = pEntity.GetComponent <AIStrategy> ().tempID; pEntity.GetComponent <AIStrategy> ().BufferFrame = 6; } } }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (!uEntity.GetComponent <AIGroupState> ().isEnable) { return; } AIEntity pLeader = uEntity.GetComponent <AIGroupState> ().pLeader; AIEntity[] pMembers = uEntity.GetComponent <AIGroupState> ().pMembers; int pid = uEntity.GetComponent <AIGroupState> ().tempGroupID; // check any foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateAnyTransfers) { if (pid != 0) { break; } int id = gstn.id; if (id == uEntity.GetComponent <AIGroupState> ().tempID) { continue; } // update logic GroupStateTransfer tTransfer = gstn.mTransfer; float rate = tTransfer(pLeader, pMembers, pid); if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f)) { GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID]; tExit(pLeader, pMembers, pid); uEntity.GetComponent <AIGroupState> ().tempID = id; GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID]; tEnter(pLeader, pMembers, pid); GroupStateRT ttRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID]; ttRT(pLeader, pMembers, pid); GroupAnimationRT ttName = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID]; string ttName_ = ttName(uEntity.GetComponent <AIGroupState>().tempGroupID); uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName_; // async data by leader for (int i = 0; i < pMembers.Length; i++) { GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID]; int pid_ = pMembers [i].GetComponent <AIGroupState> ().tempGroupID; tExit(pLeader, pMembers, pid_); pMembers [i].GetComponent <AIGroupState> ().tempID = id; GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID]; tEnter_(pLeader, pMembers, pid_); GroupStateRT ttRT_ = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID]; ttRT_(pLeader, pMembers, pid_); GroupAnimationRT ttName__ = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID]; string ttName___ = ttName__(pid_); uEntity.GetComponent <AIAnimation> ().mtempAnim = ttName___; } return; } } // check relate foreach (GroupStateTransferNode gstn in uEntity.GetComponent <AIGroupState>().mGroupStateTransfers[uEntity.GetComponent <AIGroupState>().tempID]) { if (pid != 0) { break; } int id = gstn.id; GroupStateTransfer tTransfer = gstn.mTransfer; float rate = tTransfer(pLeader, pMembers, pid); if (rate * Time.deltaTime > Random.Range(0.0f, 1.0f)) { GroupStateExit tExit = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID]; tExit(pLeader, pMembers, pid); uEntity.GetComponent <AIGroupState> ().tempID = id; GroupStateEnter tEnter = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID]; tEnter(pLeader, pMembers, pid); // async data by leader for (int i = 0; i < pMembers.Length; i++) { GroupStateExit tExit_ = uEntity.GetComponent <AIGroupState>().mGroupStateExits[uEntity.GetComponent <AIGroupState>().tempID]; int pid_ = pMembers [i].GetComponent <AIGroupState> ().tempGroupID; tExit(pLeader, pMembers, pid_); pMembers [i].GetComponent <AIGroupState> ().tempID = id; GroupStateEnter tEnter_ = uEntity.GetComponent <AIGroupState>().mGroupStateEnters[uEntity.GetComponent <AIGroupState>().tempID]; tEnter_(pLeader, pMembers, pid_); } break; } } // run the Group State node function GroupStateRT tRT = uEntity.GetComponent <AIGroupState> ().mGroupStateRTs [uEntity.GetComponent <AIGroupState> ().tempID]; tRT(pLeader, pMembers, pid); GroupAnimationRT tNameRT = uEntity.GetComponent <AIGroupState>().mAnimationDic[uEntity.GetComponent <AIGroupState> ().tempID]; string tName = tNameRT(uEntity.GetComponent <AIGroupState>().tempGroupID); uEntity.GetComponent <AIAnimation> ().mtempAnim = tName; }
public override void Update(UEntity uEntity) { base.Update(uEntity); // clear responsor data for (int i = 0; i < uEntity.GetComponent <GroupManager> ().mResponseCount; i++) { if (!uEntity.GetComponent <GroupManager> ().mResponses [i].mSucceedTeam) { uEntity.GetComponent <GroupManager> ().mResponses [i].mLeader = null; } } for (int i = 0; i < uEntity.GetComponent <GroupManager> ().mSponsorCount; i++) { // sponsor having grouping if (uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping) { if (uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer < 1.0f) { uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer += Time.deltaTime; } else { //Debug.Log (uEntity.GetComponent<GroupManager> ().mSponsors [i].tempGroupID+" "+i); // check dissolve GroupDissolve tDissolve = uEntity.GetComponent <GroupManager> ().Dictionaryforid2Dissolve [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID]; AIEntity[] pEntitys = new AIEntity[uEntity.GetComponent <GroupManager> ().mSponsors[i].memebercount]; for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++) { pEntitys [j] = uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse; } float rate = tDissolve(uEntity.GetComponent <GroupManager>().mSponsors[i].mSponsor, pEntitys); GroupStrategyExit tExit = uEntity.GetComponent <GroupManager> ().Dictionaryforid2StrategyExit [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID]; if (Random.Range(0.0f, 1.0f) < rate) { // dissolve for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++) { uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.isGrouping = false; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mSucceedTeam = false; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mLeader = null; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mGroupID = -1; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.mDissloveTimer = 10.0f; } uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount = 0; uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer = 0.0f; uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping = false; uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID = -1; tExit(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys); } uEntity.GetComponent <GroupManager> ().mSponsors [i].mDissloveTimer = 0.0f; } } else { uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount = 0; #if DEBUG AIEntity[] mEntity = AIEntity.getAllEntityWithSphere(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, uEntity.GetComponent <GroupManager> ().mCheckDistance); #else AIEntity[] mEntity = AIEntity.getAllEntityWithSphere(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, 10.0f); #endif List <ResponseNode> mResponseList = new List <ResponseNode> (); // get real responsor neighbor sponsor for (int j = 0; j < mEntity.Length; j++) { if (mEntity [j].mDissloveTimer > 0.0f) { continue; } for (int k = 0; k < uEntity.GetComponent <GroupManager>().mResponseCount; k++) { ResponseNode rn = uEntity.GetComponent <GroupManager> ().mResponses [k]; if (rn.mResponse == mEntity [j] && rn.mLeader == null) { mResponseList.Add(rn); break; } } } // responsor count int count = Mathf.Min(mResponseList.Count, uEntity.GetComponent <GroupManager>().mSponsors[i].members.Length); // Debug.Log (count); // init for (int j = 0; j < count; j++) { uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j] = mResponseList [j]; //uEntity.GetComponent<GroupManager> ().mSponsors [i].members [j].mLeader = uEntity.GetComponent<GroupManager> ().mSponsors [i].mSponsor; } uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount = count; // check Group if (uEntity.GetComponent <GroupManager> ().mSponsors [i].checkGroup()) { /* * for (int j = 0; j < count; j++) * { * uEntity.GetComponent<GroupManager> ().mSponsors [i].members [j].mLeader = uEntity.GetComponent<GroupManager> ().mSponsors [i].mSponsor; * } */ // enter group GroupStrategyEnter tEnter = uEntity.GetComponent <GroupManager> ().Dictionaryforid2StrategyEnter [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID]; GroupAllocation tAlloc = uEntity.GetComponent <GroupManager> ().Dictionaryforid2Allocation [uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID]; AIEntity[] pEntitys = new AIEntity[uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount]; for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++) { pEntitys [j] = uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse; } // enter function tEnter(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys); // alloc function int[] ids = tAlloc(uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor, pEntitys); // init sponsor uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.isGrouping = true; uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().tempGroupID = 0; EntityStrategyNode esn = new EntityStrategyNode(); esn.id = uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID; esn.tagName = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.tag; // AIGroupState temp AIGroupState mStateRT = uEntity.GetComponent <GroupManager> ().DictionaryforGroupState [esn]; uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().pLeader = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor; uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().pMembers = pEntitys; uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.GetComponent <AIGroupState> ().SimpleClone(mStateRT); for (int j = 0; j < uEntity.GetComponent <GroupManager> ().mSponsors [i].memebercount; j++) { // init Responsor uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mGroupID = ids [j]; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.isGrouping = true; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().tempGroupID = ids [j]; EntityStrategyNode esn1 = new EntityStrategyNode(); esn1.id = uEntity.GetComponent <GroupManager> ().mSponsors [i].tempGroupID; esn1.tagName = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor.tag; AIGroupState mStateRT1 = uEntity.GetComponent <GroupManager> ().DictionaryforGroupState [esn1]; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().pLeader = uEntity.GetComponent <GroupManager> ().mSponsors [i].mSponsor; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().pMembers = pEntitys; uEntity.GetComponent <GroupManager> ().mSponsors [i].members [j].mResponse.GetComponent <AIGroupState> ().SimpleClone(mStateRT1); } } } } }
public override void Update(UEntity uEntity) { base.Update(uEntity); if (uEntity.GetComponent <staComponent> ().staRate >= 0.0f) { uEntity.GetComponent <staComponent> ().staRate -= Time.deltaTime; } else { if (uEntity.GetComponent <AIEmotion> ().mtempName == "Excited") { uEntity.GetComponent <staComponent> ().staNow = Mathf.Min( uEntity.GetComponent <staComponent> ().staMax, uEntity.GetComponent <staComponent> ().staNow + uEntity.GetComponent <staComponent> ().staExcited); } else { uEntity.GetComponent <staComponent> ().staNow = Mathf.Min( uEntity.GetComponent <staComponent> ().staMax, uEntity.GetComponent <staComponent> ().staNow + uEntity.GetComponent <staComponent> ().staRecover); } uEntity.GetComponent <staComponent> ().staRate = uEntity.GetComponent <staComponent> ().staRateInit; } }
public override void Update(UEntity uEntity) { base.Update(uEntity); // 只是借用来更新几个需要每帧调用的值... uEntity.GetComponent <SSHComponent> ().atkCount = Mathf.Max(0f, uEntity.GetComponent <SSHComponent> ().atkCount - 0.3f * Time.deltaTime); // 判断盾、头部所受到的伤害 float shieldDamage = uEntity.GetComponent <SSHComponent> ().shieldFObj.GetComponent <enemyHit> ().damage; shieldDamage += uEntity.GetComponent <SSHComponent> ().shieldBObj.GetComponent <enemyHit> ().damage; float headDamage = uEntity.GetComponent <SSHComponent> ().headC.GetComponent <enemyHit> ().damage; if (shieldDamage > 0.0f || headDamage > 0.0f) { uEntity.GetComponent <getPlayer> ().engage = true; } uEntity.GetComponent <SSHComponent> ().shieldFObj.GetComponent <enemyHit> ().damage = 0.0f; uEntity.GetComponent <SSHComponent> ().shieldBObj.GetComponent <enemyHit> ().damage = 0.0f; uEntity.GetComponent <SSHComponent> ().headC.GetComponent <enemyHit> ().damage = 0.0f; uEntity.GetComponent <SSHComponent> ().shieldHPNow -= shieldDamage; uEntity.GetComponent <SSHComponent> ().HPNow -= headDamage; if (uEntity.GetComponent <shieldAI> ().powerEnd == false) { } // 先判断盾牌是否损坏 if (uEntity.GetComponent <SSHComponent> ().shieldHPNow < 20.0f) { uEntity.GetComponent <SSHComponent> ().hasShield = false; uEntity.GetComponent <SSHComponent> ().shieldBObj.SetActive(false); uEntity.GetComponent <SSHComponent> ().shieldFObj.SetActive(false); } if (uEntity.GetComponent <SSHComponent> ().hasHook) { // 有钩子 uEntity.GetComponent <SSHComponent> ().swordBObj.SetActive(false); uEntity.GetComponent <SSHComponent> ().swordFObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().back) { // 在身后 uEntity.GetComponent <SSHComponent> ().hookBObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().hookFObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().hasShield) { // 盾牌没坏 uEntity.GetComponent <SSHComponent> ().shieldBObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().shieldFObj.SetActive(false); } } else { // 在身前 uEntity.GetComponent <SSHComponent> ().hookFObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().hookBObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().hasShield) { // 盾牌没坏 uEntity.GetComponent <SSHComponent> ().shieldFObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().shieldBObj.SetActive(false); } } } else if (uEntity.GetComponent <SSHComponent> ().hasCharge) { // 有剑 uEntity.GetComponent <SSHComponent> ().hookBObj.SetActive(false); uEntity.GetComponent <SSHComponent> ().hookFObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().back) { // 在身后 uEntity.GetComponent <SSHComponent> ().swordBObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().swordFObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().shieldHPNow > 10.0f) { // 盾牌没坏 uEntity.GetComponent <SSHComponent> ().shieldBObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().shieldFObj.SetActive(false); } } else { // 在身前 uEntity.GetComponent <SSHComponent> ().swordFObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().swordBObj.SetActive(false); if (uEntity.GetComponent <SSHComponent> ().shieldHPNow > 10.0f) { // 盾牌没坏 uEntity.GetComponent <SSHComponent> ().shieldFObj.SetActive(true); uEntity.GetComponent <SSHComponent> ().shieldBObj.SetActive(false); } } } }
void Update() { if (!isStart) { return; } timer += Time.deltaTime; if (isUsingPoor) { int index = 0; for (int i = 0; i < ColumnCount; i++) { for (int j = 0; j < RowCount; j++) { if (allGameObjects [index] != null) { GameObject.Destroy(allGameObjects[index]); } index++; } } index = 0; for (int i = 0; i < ColumnCount; i++) { for (int j = 0; j < RowCount; j++) { float x1 = (RightUp.transform.position.x - LeftDown.transform.position.x) * ((float)i) / (float)ColumnCount + LeftDown.transform.position.x; float z1 = (RightUp.transform.position.z - LeftDown.transform.position.z) * ((float)j) / (float)RowCount + LeftDown.transform.position.z; Vector3 v1 = new Vector3(x1, RightUp.transform.position.y, z1); allGameObjects [index] = GameObject.Instantiate(AITemplate, v1, Quaternion.identity) as GameObject; allGameObjects [index].GetComponent <MeshRenderer> ().material.color = Color.Lerp(Color1, Color2, timer / allTime); index++; } } } else { int index = 0; for (int i = 0; i < ColumnCount; i++) { for (int j = 0; j < RowCount; j++) { if (allEntitys [index] != null) { AIPoorEntity.GetComponent <AIPoorComponent> ().DestroyEntity(allEntitys[index]); } index++; } } index = 0; for (int i = 0; i < ColumnCount; i++) { for (int j = 0; j < RowCount; j++) { float x1 = (RightUp.transform.position.x - LeftDown.transform.position.x) * ((float)i) / (float)ColumnCount + LeftDown.transform.position.x; float z1 = (RightUp.transform.position.z - LeftDown.transform.position.z) * ((float)j) / (float)RowCount + LeftDown.transform.position.z; Vector3 v1 = new Vector3(x1, RightUp.transform.position.y, z1); allEntitys [index] = AIPoorEntity.GetComponent <AIPoorComponent> ().InstantiateEntity(); allEntitys [index].GetComponent <BaseAIComponent> ().mAIRT.transform.position = v1; allEntitys [index].GetComponent <BaseAIComponent> ().mAIRT.GetComponent <MeshRenderer> ().material.color = Color.Lerp(Color1, Color2, timer / allTime); index++; } } } }
public override void Update(UEntity uEntity) { //Debug.Log ("asd"); uEntity.GetComponent <MoveComponent> ().dir = Vector3.zero; uEntity.GetComponent <MoveComponent> ().velocity = 0.0f; if (Input.GetKeyDown(KeyCode.Q)) { uEntity.GetComponent <StateComponent> ().AttackState = true; } if (Input.GetKey(KeyCode.W)) { uEntity.GetComponent <MoveComponent> ().dir += Vector3.left; uEntity.GetComponent <MoveComponent> ().velocity = 3.0f; } if (Input.GetKey(KeyCode.A)) { uEntity.GetComponent <MoveComponent> ().dir += Vector3.up; uEntity.GetComponent <MoveComponent> ().velocity = 3.0f; } if (Input.GetKey(KeyCode.S)) { uEntity.GetComponent <MoveComponent> ().dir += Vector3.down; uEntity.GetComponent <MoveComponent> ().velocity = 3.0f; } if (Input.GetKey(KeyCode.D)) { uEntity.GetComponent <MoveComponent> ().dir += Vector3.right; uEntity.GetComponent <MoveComponent> ().velocity = 3.0f; } }
// 要注意到之后的逻辑,在节点中,只靠是否insight来进行判断的 public override void Update(UEntity uEntity) { base.Update(uEntity); AIEntity ai = (AIEntity)uEntity; float isssi = 0.0f; // 实时更新警觉值半径大小 if (uEntity.GetComponent <getPlayer> ().engage == false && uEntity.GetComponent <getPlayer> ().vigilance) { isssi = uEntity.GetComponent <getPlayer> ().vigilanceTime; } else if (uEntity.GetComponent <getPlayer> ().engage == false && uEntity.GetComponent <getPlayer> ().search) { isssi = uEntity.GetComponent <getPlayer> ().searchTime + uEntity.GetComponent <getPlayer> ().vtinit; } // 可视化警觉值 ai.GetComponent <getPlayer> ().vs.transform.localScale = new Vector3(isssi / 4, 0.1f, isssi / 4); if (uEntity.GetComponent <getPlayer> ().getNoise) { uEntity.GetComponent <getPlayer> ().getNoise = false; uEntity.GetComponent <getPlayer> ().insight = true; uEntity.GetComponent <getPlayer> ().suspensionPoint = ai.PlayerPos; time = uEntity.GetComponent <getPlayer> ().time; return; } if (time > 0.0f) // 没发现一次玩家,就会保持0.2s的警觉时间 { time -= Time.deltaTime; return; } Transform p = ai.mPlayer.transform; Transform a = uEntity.GetComponent <BaseAIComponent> ().mAIRT.transform; // 超出视线范围,修正insight为false if (Vector3.Distance(a.position, p.position) > uEntity.GetComponent <getPlayer> ().sightRange) { uEntity.GetComponent <getPlayer> ().insight = false; return; } // 玩家和AI的位置信息 Vector3 v = ((AIEntity)uEntity).AIPos; // 判断角度是否符合 if (Vector3.Angle(a.forward, p.position - a.position) > uEntity.GetComponent <getPlayer> ().sightAngle) { uEntity.GetComponent <getPlayer> ().insight = false; return; } // 发出两条射线,分别对应玩家站立、下蹲姿态 Ray rayh = new Ray(a.position + Vector3.up * 0.8f, p.position - a.position); Ray rayl = new Ray(a.position + Vector3.up * 0.5f, p.position - a.position); float dis = Vector3.Distance(a.position, p.position); dis -= 0.5f; RaycastHit hit; int targetMask = LayerMask.GetMask("Barrier"); // 射线只检测从自身到玩家的长度有没有东西 if (Physics.Raycast(rayh, out hit, dis, targetMask) && Physics.Raycast(rayl, out hit, dis, targetMask)) { // 只有两个视点都被障碍物挡住了,才是没看到玩家 uEntity.GetComponent <getPlayer> ().insight = false; return; } else { uEntity.GetComponent <getPlayer> ().insight = true; // 更新玩家位置 uEntity.GetComponent <getPlayer> ().suspensionPoint = ai.PlayerPos; time = uEntity.GetComponent <getPlayer> ().time; Debug.DrawLine(v + Vector3.up * 0.8f, v + Vector3.up * 0.8f + a.forward * dis, Color.red, 2.0f, true); Debug.DrawLine(v + Vector3.up * 0.5f, v + Vector3.up * 0.5f + a.forward * dis, Color.red, 2.0f, true); return; } }
public override void Update(UEntity uEntity) { base.Update(uEntity); //Debug.Log (uEntity.GetComponent<AIMove> ().mVelocity+" "+uEntity.GetComponent<AIMove> ().mDirection+s); if (uEntity.GetComponent <AIMove> ().mVelocity == 0.0f && uEntity.GetComponent <AIMove>().mMoveFunc != MoveFunc.JUSTROTATE) { return; } // RVO if (uEntity.GetComponent <AIMove> ().mMoveFunc == MoveFunc.RVO) { GameObject tg = getGameObjectFromEntity(uEntity); RVOObject[] RVO_AI = FindAIEntity(tg.transform.position, maxDis, tg); RVOObject[] RVO_Obestacle = FindObestacle(tg.transform.position, maxDis); Vector2 VA = uEntity.GetComponent <AIMove> ().mDirection *uEntity.GetComponent <AIMove> ().mVelocity; Vector2 PA = tg.transform.position; ArrayList RVO_All = new ArrayList(); for (int j = 0; j < RVO_AI.Length; j++) { Vector2 VB = RVO_AI [j].mvelocity; Vector2 PB = RVO_AI [j].mpos; RVO_BA BA = new RVO_BA(); BA.avoidRadius = twiceRadius; BA.trans.Set(PA.x + 0.5f * (VA.x + VB.x), PA.y + 0.5f * (VA.y + VB.y)); BA.trans.Set(PA.x + 0.5f * (VA.x + VB.x), PA.y + 0.5f * (VA.y + VB.y)); BA.dist = Vector2.Distance(PA, PB); float theta_BA = Mathf.Atan2(PB.y - PA.y, PB.x - PA.y); if (twiceRadius > BA.dist) { BA.dist = twiceRadius; } float thetaBAOrt = Mathf.Asin(twiceRadius / BA.dist); float thetaOrtLeft = theta_BA + thetaBAOrt; BA.leftBound.Set(Mathf.Cos(thetaOrtLeft), Mathf.Sin(thetaOrtLeft)); float thetaOrtRight = theta_BA - thetaBAOrt; BA.rightBound.Set(Mathf.Cos(thetaOrtRight), Mathf.Sin(thetaOrtRight)); RVO_All.Add(BA); } for (int j = 0; j < RVO_Obestacle.Length; j++) { Vector2 VB = Vector2.zero; Vector2 PB = RVO_Obestacle [j].mpos; RVO_BA BA = new RVO_BA(); BA.trans.Set(PA.x + 0.5f * (VA.x + VB.x), PA.y + 0.5f * (VA.y + VB.y)); BA.dist = Vector2.Distance(PA, PB); float theta_BA = Mathf.Atan2(PB.y - PA.y, PB.x - PA.x); float rad = 0.5f * 1.5f; BA.avoidRadius = rad + RoboRadius; if (BA.avoidRadius > BA.dist) { BA.dist = BA.avoidRadius; } float thetaBAOrt = Mathf.Asin(BA.avoidRadius / BA.dist); float thetaOrtLeft = theta_BA + thetaBAOrt; BA.leftBound.Set(Mathf.Cos(thetaOrtLeft), Mathf.Sin(thetaOrtLeft)); float thetaOrtRight = theta_BA - thetaBAOrt; BA.rightBound.Set(Mathf.Cos(thetaOrtRight), Mathf.Sin(thetaOrtRight)); RVO_All.Add(BA); } Vector2 velocityMY = new Vector2(uEntity.GetComponent <AIMove> ().mDirection.x, uEntity.GetComponent <AIMove> ().mDirection.z); velocityMY *= uEntity.GetComponent <AIMove> ().mVelocity; Vector2 velocity = intersect(velocityMY, tg.transform.position, RVO_All); uEntity.GetComponent <AIMove> ().mDirection = (new Vector3(velocity.x, 0, velocity.y)).normalized; Vector3 mTranslation = (uEntity.GetComponent <AIMove>().mDirection.normalized); mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); GameObject tObject; if (uEntity.GetComponent <BaseAIComponent> () != null) { tObject = uEntity.GetComponent <BaseAIComponent> ().mAIRT; } else { tObject = ((SimpleAI)uEntity).mAIRT; } tObject.transform.forward = mTranslation.normalized; tObject.transform.position += uEntity.GetComponent <AIMove>().mVelocity *Time.deltaTime *tObject.transform.forward; } else if (uEntity.GetComponent <AIMove> ().mMoveFunc == MoveFunc.Complex) { int layermask = 1 << LayerMask.NameToLayer("Collision"); GameObject tObject; if (uEntity.GetComponent <BaseAIComponent> () != null) { tObject = uEntity.GetComponent <BaseAIComponent> ().mAIRT; } else { tObject = ((SimpleAI)uEntity).mAIRT; } Vector4 dir1v4 = Matrix4x4.Rotate(Quaternion.Euler(0, 45, 0)) * (new Vector4(uEntity.GetComponent <AIMove> ().mDirection.x, uEntity.GetComponent <AIMove> ().mDirection.y, uEntity.GetComponent <AIMove> ().mDirection.z, 1.0f)); Vector4 dir2v4 = Matrix4x4.Rotate(Quaternion.Euler(0, -45, 0)) * (new Vector4(uEntity.GetComponent <AIMove> ().mDirection.x, uEntity.GetComponent <AIMove> ().mDirection.y, uEntity.GetComponent <AIMove> ().mDirection.z, 1.0f)); Vector3 dir1 = new Vector3(dir1v4.x, dir1v4.y, dir1v4.z); Vector3 dir2 = new Vector3(dir2v4.x, dir2v4.y, dir2v4.z); //Vector3. RaycastHit hit = new RaycastHit(); // if raycast hit it if (Physics.Raycast(tObject.transform.position, uEntity.GetComponent <AIMove> ().mDirection, out hit, 7.0f, layermask) || Physics.Raycast(tObject.transform.position, dir1, out hit, 7.0f, layermask) || Physics.Raycast(tObject.transform.position, dir2, out hit, 7.0f, layermask)) { Vector3 hitNormal = hit.normal; //Debug.Log (hit.transform.position+" "+hit.normal); hitNormal.y = 0.0f; float disToAvoid = hit.distance; if (disToAvoid > 6) { Vector3 mTranslation = uEntity.GetComponent <AIMove> ().mDirection.normalized *uEntity.GetComponent <AIMove> ().mVelocity + hitNormal.normalized * uEntity.GetComponent <AIMove> ().mVelocity * 0.2f; mTranslation *= Time.deltaTime; tObject.transform.forward = mTranslation.normalized; tObject.transform.position += mTranslation.magnitude * tObject.transform.forward; // Debug.Log ("5-7"); } else if (disToAvoid > 3f) { Vector3 pullForce = Vector3.Cross(hitNormal, Vector3.up).normalized; float PdotD = Vector3.Dot(uEntity.GetComponent <AIMove> ().mDirection.normalized, pullForce.normalized); if (Mathf.Abs(PdotD) < 0.05f) { PdotD = 0.0f; } if (PdotD > 0) { Vector3 mTranslation = uEntity.GetComponent <AIMove> ().mDirection.normalized *uEntity.GetComponent <AIMove> ().mVelocity; mTranslation += pullForce * uEntity.GetComponent <AIMove> ().mVelocity * 0.3f; mTranslation *= Time.deltaTime; mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); // tObject.transform.forward = new Vector3(mTranslation.normalized.x,0,mTranslation.normalized.z); tObject.transform.forward = mTranslation.normalized; tObject.transform.position += mTranslation.magnitude * tObject.transform.forward; //Debug.Log ("pull"); } else { Vector3 mTranslation = uEntity.GetComponent <AIMove> ().mDirection.normalized; mTranslation += -pullForce * 0.3f; mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); // tObject.transform.forward = new Vector3(mTranslation.normalized.x,0,mTranslation.normalized.z); tObject.transform.forward = mTranslation.normalized; tObject.transform.position += uEntity.GetComponent <AIMove> ().mVelocity *tObject.transform.forward *Time.deltaTime; } } else { Vector3 paraSpeed = Vector3.Cross(hitNormal, Vector3.up).normalized; float PdotD = Vector3.Dot(uEntity.GetComponent <AIMove> ().mDirection.normalized, paraSpeed); if (Mathf.Abs(PdotD) < 0.05f) { PdotD = 0.0f; } Vector3 mTranslation = paraSpeed; mTranslation += uEntity.GetComponent <AIMove> ().mDirection; mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); tObject.transform.forward = mTranslation.normalized; tObject.transform.position += uEntity.GetComponent <AIMove> ().mVelocity *tObject.transform.forward *Time.deltaTime; } } else { Vector3 mTranslation = (uEntity.GetComponent <AIMove>().mDirection.normalized); mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); tObject.transform.forward = mTranslation.normalized; tObject.transform.position += tObject.transform.forward * uEntity.GetComponent <AIMove>().mVelocity *Time.deltaTime; } } else { Vector3 mTranslation = (uEntity.GetComponent <AIMove>().mDirection.normalized); mTranslation = new Vector3(mTranslation.x, 0, mTranslation.z); GameObject tObject; if (uEntity.GetComponent <BaseAIComponent> () != null) { tObject = uEntity.GetComponent <BaseAIComponent> ().mAIRT; } else { tObject = ((SimpleAI)uEntity).mAIRT; } tObject.transform.forward = mTranslation.normalized; tObject.transform.position += tObject.transform.forward * uEntity.GetComponent <AIMove>().mVelocity *Time.deltaTime; } }