|
|
@@ -114,7 +114,7 @@ public class Wolf : TargetAnimal
|
|
|
state.lockingTarget = true;
|
|
|
needAmbush = false;
|
|
|
} else {
|
|
|
- //未锁定目标阶段是被击退,因为可能会再次满足z路径条件,因此需要重置Z路径记录
|
|
|
+ //未锁定目标阶段时被击退,因为可能会再次满足z路径条件,因此需要重置Z路径记录
|
|
|
if (!state.lockingTarget) ResetZPathRecord();
|
|
|
CancelLockTarget(1);
|
|
|
RunAwayFromHunter();
|
|
|
@@ -360,17 +360,17 @@ public class Wolf : TargetAnimal
|
|
|
//在敌人身边奔跑徘徊
|
|
|
void RunAroundHunter(bool quickly) {
|
|
|
float baseDistance = 10;
|
|
|
- float baseDistanceMoveRange = 10;
|
|
|
+ float baseDistanceMoveRange = 5;
|
|
|
Vector3 standardPointer = animalsBaseT.forward;
|
|
|
Vector3 pointerWithLen = standardPointer.normalized * (baseDistance + Random.value * baseDistanceMoveRange);
|
|
|
- pointerWithLen = Quaternion.AngleAxis(-40f + Random.value * 80f, Vector3.up) * pointerWithLen;
|
|
|
+ pointerWithLen = Quaternion.AngleAxis(Random.Range(-20f, 23f), Vector3.up) * pointerWithLen;
|
|
|
Vector3 newPos = animalsBaseT.position + pointerWithLen;
|
|
|
SetDestination(newPos);
|
|
|
state.moveSlowly = !quickly;
|
|
|
state.moveQuickly = quickly;
|
|
|
agent.speed = quickly ? 5f : 0.8f;
|
|
|
}
|
|
|
- //Z字型路径缓慢移动
|
|
|
+ //Z字型路径
|
|
|
Queue<Vector3> zPathPoints = new Queue<Vector3>();
|
|
|
bool canCreateZPath = true;
|
|
|
void ResetZPathRecord() {
|
|
|
@@ -390,38 +390,45 @@ public class Wolf : TargetAnimal
|
|
|
}
|
|
|
//构建Z字型路径
|
|
|
zPathPoints.Clear();
|
|
|
- Vector3 standardPos = animalsBaseT.forward;
|
|
|
- Vector3 hunterPos = hunterPosition;
|
|
|
- Vector3 pointerToMe = GetPointerHunterToMe().normalized;
|
|
|
- Vector3 pointer1 = Quaternion.AngleAxis(120, Vector3.up) * pointerToMe;
|
|
|
- Vector3 pointer2 = Quaternion.AngleAxis(-120, Vector3.up) * pointerToMe;
|
|
|
+ Vector3 standardVec = animalsBaseT.forward;
|
|
|
+ Vector3 hunterPos = animalsBaseT.position;
|
|
|
Vector3 myPos = this.transform.position;
|
|
|
- int[] pointerSeq = {1, 2, 1};
|
|
|
- bool isReverse = Random.value < 0.5;
|
|
|
- foreach (int seqID in pointerSeq)
|
|
|
- {
|
|
|
- Vector3 lastMyPos = myPos;
|
|
|
- if (seqID == 1) myPos = myPos + (isReverse ? pointer2 : pointer1) * 5;
|
|
|
- if (seqID == 2) myPos = myPos + (isReverse ? pointer1 : pointer2) * 10;
|
|
|
- hunterPos.y = myPos.y;
|
|
|
- Vector3 hunterToMe = myPos - hunterPos;
|
|
|
- float angle = Vector3.Angle(hunterToMe, standardPos);
|
|
|
- float minDistance = 10;
|
|
|
- //如果下一个构建的坐标在猎手身后或者距离猎手低于指定距离
|
|
|
- if (angle > 90 || Vector3.Distance(hunterPos, myPos) < minDistance) {
|
|
|
- Vector3 hunterToMe2 = lastMyPos - hunterPos;
|
|
|
- if (hunterToMe2.magnitude > minDistance + 2) {
|
|
|
- Vector3 displace = (hunterToMe2).normalized * minDistance;
|
|
|
- myPos = hunterPos + displace;
|
|
|
- zPathPoints.Enqueue(myPos);
|
|
|
+ float minDistance = 10;
|
|
|
+ float maxDistance = 25;
|
|
|
+ while (true) {
|
|
|
+ myPos.y = hunterPos.y;
|
|
|
+ float distance = Vector3.Distance(myPos, hunterPos);
|
|
|
+ if (distance > minDistance) {
|
|
|
+ Vector3 vecToMyPos = myPos - hunterPos;
|
|
|
+ //判断位置在猎人左边还是右边
|
|
|
+ float crossY = Vector3.Cross(standardVec, vecToMyPos).y;
|
|
|
+ float nextAngle;
|
|
|
+ if (crossY >= 0) { //在右边
|
|
|
+ nextAngle = Random.Range(-20f, -10f);//下次就向左边走
|
|
|
+ } else { //在左边
|
|
|
+ nextAngle = Random.Range(13f, 22f);;//下次就向右边走
|
|
|
}
|
|
|
- canCreateZPath = false;
|
|
|
- break;
|
|
|
- } else {
|
|
|
+ float nextDistance = distance - Random.Range(3.5f, 4.5f);
|
|
|
+ if (nextDistance > maxDistance) {
|
|
|
+ nextDistance = maxDistance;
|
|
|
+ }
|
|
|
+ if (nextDistance < minDistance) {
|
|
|
+ nextDistance = minDistance;
|
|
|
+ }
|
|
|
+ if (Mathf.Abs(nextDistance - distance) < 1.2f) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Vector3 displace = (Quaternion.AngleAxis(nextAngle, Vector3.up) * standardVec) * nextDistance;
|
|
|
+ myPos = hunterPos + displace;
|
|
|
zPathPoints.Enqueue(myPos);
|
|
|
+ // Debug.Log(Quaternion.AngleAxis(-180f, Vector3.up) * (myPos - hunterPos));
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ canCreateZPath = false;
|
|
|
+ }
|
|
|
+
|
|
|
//停留
|
|
|
void Stay(bool correct = false) {
|
|
|
if (state.moving || correct) {
|