|
|
@@ -2,6 +2,7 @@ using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using UnityEngine.AI;
|
|
|
+using DG.Tweening;
|
|
|
|
|
|
public class Wolf : TargetAnimal
|
|
|
{
|
|
|
@@ -175,24 +176,70 @@ public class Wolf : TargetAnimal
|
|
|
this.willMoveTime = Random.value * 3 + 5;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //起跳点
|
|
|
+ Vector3 jumpPoint;
|
|
|
+ //落地点
|
|
|
+ Vector3 landPoint;
|
|
|
//攻击
|
|
|
void Attack() {
|
|
|
state.ResetActionState();
|
|
|
state.attacking = true;
|
|
|
curAnimIndex = -1; /*注意:这样可避免狼两次使用同一攻击动作而第二次无法播放的情况 */
|
|
|
int hurtValue = 2;
|
|
|
- if (Random.value < 0.5) {
|
|
|
+ if (canAttackID == "A") {
|
|
|
state.attackA = true;
|
|
|
- } else {
|
|
|
+ #region //起点和终点计算
|
|
|
+ jumpPoint = this.transform.position;
|
|
|
+ Vector3 hunterPos = hunterPosition;
|
|
|
+ hunterPos.y = jumpPoint.y;
|
|
|
+ Vector3 deltaPointer = jumpPoint - hunterPos;
|
|
|
+ landPoint = hunterPos + deltaPointer.normalized * 2f;
|
|
|
+ #endregion
|
|
|
+ Vector3 displace = landPoint - jumpPoint;
|
|
|
+ float baseoffset = this.agent.baseOffset;
|
|
|
+ Sequence seq = DOTween.Sequence();
|
|
|
+ seq.Append(DOTween.To(() => 0f, value => {
|
|
|
+ this.transform.position = jumpPoint + displace * value;
|
|
|
+ if (value < 0.5) {
|
|
|
+ this.agent.baseOffset = baseoffset + value;
|
|
|
+ } else {
|
|
|
+ this.agent.baseOffset = baseoffset + (1 - value);
|
|
|
+ }
|
|
|
+ }, 1f, 0.6f));
|
|
|
+ seq.AppendCallback(delegate() {
|
|
|
+ this.transform.position = landPoint;
|
|
|
+ if (!state.dead) onAttack?.Invoke(this, hurtValue);
|
|
|
+ });
|
|
|
+ seq.Append(DOTween.To(() => 0f, value => {
|
|
|
+ this.transform.position = landPoint;
|
|
|
+ }, 1f, 0.634f));
|
|
|
+ seq.AppendCallback(delegate() {
|
|
|
+ if (!state.dead) stopAniAttackA();
|
|
|
+ this.transform.position = landPoint;
|
|
|
+ });
|
|
|
+ seq.Append(DOTween.To(() => 0f, value => {
|
|
|
+ this.transform.position = landPoint;
|
|
|
+ }, 1f, 0.1f)); //通过dotween是它不被动画的位移影响;
|
|
|
+ } else if (canAttackID == "B") {
|
|
|
state.attackB = true;
|
|
|
hurtValue = 3;
|
|
|
+ onAttack?.Invoke(this, hurtValue);
|
|
|
}
|
|
|
- onAttack?.Invoke(this, hurtValue);
|
|
|
}
|
|
|
//跑到能攻击玩家的坐标点
|
|
|
+ string canAttackID = null;
|
|
|
void RunToAttackHunter() {
|
|
|
+ float needDistance;
|
|
|
+ if (Random.value < 0.33f) {
|
|
|
+ needDistance = 2;
|
|
|
+ canAttackID = "B";
|
|
|
+ } else {
|
|
|
+ needDistance = 8;
|
|
|
+ canAttackID = "A";
|
|
|
+ }
|
|
|
Vector3 standardPointer = animalsBaseT.forward;
|
|
|
- Vector3 newPos = animalsBaseT.position + standardPointer * 1.5f;
|
|
|
+ Vector3 newPos = animalsBaseT.position + standardPointer * needDistance;
|
|
|
SetDestination(newPos);
|
|
|
state.moveQuickly = true;
|
|
|
agent.speed = 5f;
|
|
|
@@ -292,6 +339,9 @@ public class Wolf : TargetAnimal
|
|
|
bool isAniAttakA() {
|
|
|
return curAnimIndex == 1;
|
|
|
}
|
|
|
+ void stopAniAttackA() {
|
|
|
+ ap.StopAnimation(1);
|
|
|
+ }
|
|
|
void playAniAttakB() {
|
|
|
ap.play(curAnimIndex = 0, WrapMode.Once);
|
|
|
}
|