Commit 01127474 authored by czy's avatar czy

修复动画Bug

parent 6136edc1
This diff is collapsed.
This diff is collapsed.
......@@ -153,19 +153,19 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: LegSweep
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: HurricaneKick
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
......@@ -198,8 +198,8 @@ AnimatorStateTransition:
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.89285713
m_HasExitTime: 0
m_ExitTime: 0.8928571
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
......@@ -248,9 +248,9 @@ AnimatorStateTransition:
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionDuration: 0.18607777
m_TransitionOffset: 0
m_ExitTime: 0.75
m_ExitTime: 0.7942538
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
......@@ -276,7 +276,7 @@ AnimatorStateTransition:
m_TransitionDuration: 0.03374338
m_TransitionOffset: 0
m_ExitTime: 0.9815945
m_HasExitTime: 0
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
......
This diff is collapsed.
......@@ -30,7 +30,7 @@ Transform:
m_GameObject: {fileID: 7483224581113721909}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0.429, z: -0.426}
m_LocalScale: {x: 0.26094243, y: 1.0665408, z: 1.0888398}
m_LocalScale: {x: 0.26094243, y: 1.0665408, z: 1.6568875}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
......@@ -50,7 +50,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7483224581113721909}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
......
......@@ -50,7 +50,7 @@ MeshRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6039842180593449807}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
......
......@@ -42,10 +42,12 @@ public class AIMove : MonoBehaviour
FindFood=0, //找食物
GoToPathPos0=1, //去pos0
Push=2, //推墙
TurnBackToPathPos0=3 //返回Pos0
TurnBackToPathPos0=3, //返回Pos0
PlayBoss=4
}
public AIState aiState;
private float vertigoTime = 0.0f;
private AnimationManager animationManager;
// Start is called before the first frame update
void Start()
......@@ -56,6 +58,7 @@ public class AIMove : MonoBehaviour
//ChangeModel();
RandomFoodNumberToPush = Random.Range(1,11);
aiState = AIState.FindFood;
animationManager = GetComponentInChildren<AnimationManager>();
}
......@@ -76,9 +79,12 @@ public class AIMove : MonoBehaviour
//推墙
//targetObj = targetWall;
aiState = AIState.GoToPathPos0; //到路径起点,准备去推墙
}else if (RandomFoodNumberToPush <= HaveFoodNumber && targetWall == null)
{
aiState = AIState.PlayBoss;
}
if(scale >= (1 + MaxFood * addScale))
if (scale >= (1 + MaxFood * addScale))
{
scale = 1 + MaxFood * addScale;
}
......@@ -230,6 +236,7 @@ public class AIMove : MonoBehaviour
////print("改变状态为回到起点1");
//aiState = AIState.TurnBackToPathPos0;
aiState = AIState.PlayBoss;
targetObj = GameObject.FindGameObjectWithTag("Boss");
}
else
......@@ -247,6 +254,23 @@ public class AIMove : MonoBehaviour
targetObj = GetTargetPos();
//print("获取新目标:" + targetObj);
}
break;
case AIState.PlayBoss:
targetObj = GameObject.FindGameObjectWithTag("Boss");
if (targetObj == null)
{
aiState = AIState.FindFood;
}
if (scale <= 1)
{
scale = 1;
RandomFoodNumberToPush = Random.Range(1, 11);
HaveFoodNumber = 0;
aiState = AIState.FindFood;
}
break;
default:
Debug.LogError(aiState);
......@@ -270,21 +294,36 @@ public class AIMove : MonoBehaviour
//眩晕
vertigoTime -= Time.deltaTime;
vertigoEffect.gameObject.SetActive(true);
animator.SetBool("Vertigo", true);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
//animator.SetBool("Vertigo", true);
//animator.SetBool("Push", false);
//animator.SetBool("Punch", false);
animationManager.ChangeAnimatorState(AnimationState.Vertigo);
}
else
{
vertigoEffect.gameObject.SetActive(false);
vertigoTime = 0;
animator.SetBool("Vertigo", false);
//animator.SetBool("Vertigo", false);
animationManager.VertigoToAwake();
Move();
}
//调用一次性方法
if (targetWall == null)
{
animationManager.NotPush();
}
if (GameObject.FindGameObjectWithTag("Boss") == null)
{
animationManager.ResetPunch();
}
}
......@@ -312,114 +351,6 @@ public class AIMove : MonoBehaviour
////AI策略,需要每一帧都执行放到FixedUpdate中。
//public void DoStraightLine()
//{
// deltaX = 0;
//}
////AI策略,需要每一帧都执行放到FixedUpdate中。
//public void DoPickUpPropsAndGold()
//{
// if (!Grounded)
// {
// }
// else
// {
// //在地面上,计算导航去目标位置,每次移动的距离。
// if (targetObj != null)
// {
// if (targetObj.transform.position.x - transform.position.x > 0.3f) //误差值0.3
// {
// deltaX = HSpeed * Time.deltaTime;
// }
// else if (targetObj.transform.position.x - transform.position.x < -0.3f)
// {
// deltaX = -HSpeed * Time.deltaTime;
// }
// else
// {
// deltaX = 0;
// }
// }
// }
//}
//AI策略,需要每一帧都执行放到FixedUpdate中。
//public void DoAvoidObstaclesAndPickUp(string obstaclesTag)
//{
// Debug.DrawRay(raySeeWayPos.position, raySeeWayPos.forward * 10f, Color.red);
// RaycastHit seeHit;
// bool isSee = Physics.Raycast(raySeeWayPos.position, raySeeWayPos.forward, out seeHit, 6.0f);
// if (seeHit.collider != null)
// {
// //print("看见物体:" + seeHit.collider.tag);
// if (seeHit.collider.tag == obstaclesTag)//if (seeHit.collider.tag == "Prickle")
// {
// //前方有障碍物
// //deltaX = 0;//将寻金币的横向的位移变为0;
// //seeHit.collider.bounds.size.x
// //seeHit.transform.position.x - seeHit.collider.bounds.size.x * 0.5f
// //minX = seeHit.transform.position.x - seeHit.collider.bounds.size.x * 0.5f - 0.5f;
// //maxX = seeHit.transform.position.x - seeHit.collider.bounds.size.x * 0.5f + 0.5f;
// maxZ = seeHit.transform.position.z + seeHit.collider.bounds.size.z * 0.5f + 0.5f;
// if (transform.position.x < seeHit.transform.position.x)
// {
// //去左边
// avoidX = seeHit.transform.position.x - seeHit.collider.bounds.size.x * 0.5f - 0.5f;
// AvoidDir = -1;
// }
// else
// {
// //去右边
// avoidX = seeHit.transform.position.x + seeHit.collider.bounds.size.x * 0.5f + 0.5f;
// AvoidDir = 1;
// }
// }
// }
// if (transform.position.z < maxZ)
// {
// //print("前方有障碍物,开始躲避AvoidDir:"+ AvoidDir+ "transform.position.x:"+ transform.position.x + "avoidX:" + avoidX);
// //前方右障碍物,开始躲避。
// //关闭金币导航
// deltaX = 0;
// //开始左右躲避
// if (AvoidDir == -1 && transform.position.x >= avoidX)
// {
// //向左移动
// //print("向左移动");
// deltaX = -HSpeed * Time.deltaTime;
// }
// else if (AvoidDir == -1 && transform.position.x < avoidX)
// {
// //向左躲避成功
// AvoidDir = 0;
// }
// else if (AvoidDir == 1 && transform.position.x <= avoidX)
// {
// //向右走
// deltaX = HSpeed * Time.deltaTime;
// //print("向右移动");
// }
// else if (AvoidDir == 1 && transform.position.x > avoidX)
// {
// //躲避成功
// AvoidDir = 0;
// }
// }
//}
//获取目标点
public GameObject GetTargetPos()
{
......
......@@ -8,7 +8,7 @@ public class BossMove : MonoBehaviour
[Tooltip("控制向前的速度。")]
public float VSpeed = 10.0f;
public int life = 30;
public int MaxLife = 30;
private int MaxLife;
public float scale = 1;
public float MinScale = 0.2f;
[Header("目标")]
......@@ -33,6 +33,7 @@ public class BossMove : MonoBehaviour
public int EnemyNumber = 0;
public float Timer1 = 5;
public bool isDeltaTime = false;
private bool isAttacking=false;
public enum BossState
{
......@@ -45,6 +46,7 @@ public class BossMove : MonoBehaviour
void Start()
{
MaxLife = life;
characterController = GetComponentInChildren<CharacterController>();
//获取animator组件
animator = GetComponentInChildren<Animator>();
......@@ -160,8 +162,7 @@ public class BossMove : MonoBehaviour
if (Vector3.Distance(pos1, pos2) < 10f)
{
xDelta = 0;
zDelta = 0;
isAttacking = true;
if (EnemyNumber >= 2&& !isDeltaTime)
{
Timer1 -= Time.deltaTime;
......@@ -182,9 +183,10 @@ public class BossMove : MonoBehaviour
}
else
{
isAttacking = false;
animator.SetBool("LegSweep", false);
animator.SetBool("HurricaneKick", false);
bossAttack.attackType = AttackType.Null;
//bossAttack.attackType = AttackType.Null;
}
}
else
......@@ -206,7 +208,14 @@ public class BossMove : MonoBehaviour
angle = -Mathf.Abs(angle);
}
transform.localEulerAngles = new Vector3(0, angle, 0);
//print("AI开始移动:"+ new Vector3(xDelta, yDelta, zDelta));
if (isAttacking)
{
xDelta = 0;
zDelta = 0;
}
print("isAttacking:" + isAttacking+"AI开始移动:" + new Vector3(xDelta, yDelta, zDelta));
characterController.Move(new Vector3(xDelta, yDelta, zDelta));//移动
//移动
......@@ -266,6 +275,5 @@ public class BossMove : MonoBehaviour
private void OnDestroy()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum AnimationState
{
Vertigo = 1,
Punch = 2,
Push = 3,
Idle=4,
Run=5,
}
public class AnimationManager : MonoBehaviour
{
private Animator animator;
private bool isCanPush = true;
private bool IsVertigoToAwake = false;
private bool IsCanResetPunch = true;
void Start()
{
animator = GetComponentInChildren<Animator>();
}
// Update is called once per frame
void Update()
{
}
public void ChangeAnimatorState(AnimationState state)
{
//print(gameObject.name + ",ChangeAnimatorState:" + state);
switch (state)
{
case AnimationState.Vertigo: //眩晕
animator.SetBool("Vertigo", true);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
//animator.SetLayerWeight(1, 1);
IsVertigoToAwake = true;
break;
case AnimationState.Punch:
animator.SetBool("Vertigo", false);
animator.SetBool("Push", false);
animator.SetBool("Punch", true);
animator.SetLayerWeight(1, 1);
break;
case AnimationState.Push:
animator.SetBool("Vertigo", false);
animator.SetBool("Push", true);
animator.SetBool("Punch", false);
animator.SetLayerWeight(1, 1);
break;
case AnimationState.Idle:
animator.SetBool("Vertigo", false);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
animator.SetLayerWeight(1, 0);
break;
case AnimationState.Run:
animator.SetBool("Vertigo", false);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
animator.SetLayerWeight(1, 0);
break;
default:
Debug.LogError(state);
break;
}
}
/// <summary>
/// 不需要Push时调用
/// </summary>
public void NotPush()
{
if (!isCanPush) return;
//print("禁用Push");
isCanPush = false;
animator.SetBool("Push", false);
animator.SetLayerWeight(1, 0);
}
/// <summary>
/// 眩晕后调用才能有效
/// </summary>
public void VertigoToAwake()
{
if (!IsVertigoToAwake) return;
IsVertigoToAwake = false;
print("VertigoToAwake");
animator.SetBool("Vertigo", false);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
animator.SetLayerWeight(1, 0);
}
/// <summary>
///一次方法,Boss死亡后调用
/// </summary>
public void ResetPunch()
{
if (!IsCanResetPunch) return;
IsCanResetPunch = false;
print("ResetPunch");
animator.SetBool("Punch", false);
animator.SetLayerWeight(1, 0);
}
}
fileFormatVersion: 2
guid: 139e7c9d582680a4681f59bf4f151f81
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowTargetPos : MonoBehaviour
{
public Transform pos;
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = pos.position;
}
}
fileFormatVersion: 2
guid: 5a21b8fedb18cae4789aae35d50efa2e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -49,7 +49,7 @@ public class RandomFood : MonoBehaviour
/// <param name="number"></param>
public void GenerateRandomFood(int number)
{
print("生成食物个数:"+number);
//print("生成食物个数:"+number);
for (int i = 0; i < number; i++)
{
GameObject obj = getRandomFoodObj();
......
......@@ -13,7 +13,8 @@ public class AttackTrigger : MonoBehaviour
public ParticleSystem hitEffects;
[HideInInspector]
public GameObject hitPos;
public AnimationManager animationManager;
void Start()
{
}
......@@ -28,11 +29,13 @@ public class AttackTrigger : MonoBehaviour
//print("进入。" + other.name);
if (OtherTagList.Contains(other.tag))//if (other.tag == "Competitor")
{
ChangeAnimationPunchState(true);
//ChangeAnimationPunchState(true);
animationManager.ChangeAnimatorState(AnimationState.Punch);
}
else if(other.gameObject == targetWall)
{
ChangeAnimationPushState(true);
//ChangeAnimationPushState(true);
animationManager.ChangeAnimatorState(AnimationState.Push);
}
}
......@@ -73,41 +76,43 @@ public class AttackTrigger : MonoBehaviour
//print("退出。"+ other.name);
if (OtherTagList.Contains(other.tag))
{
ChangeAnimationPunchState(false);
//ChangeAnimationPunchState(false);
animationManager.ChangeAnimatorState(AnimationState.Idle);
}
else if(other.gameObject == targetWall)
{
ChangeAnimationPushState(false);
//ChangeAnimationPushState(false);
animationManager.ChangeAnimatorState(AnimationState.Idle);
}
}
//Push
public void ChangeAnimationPushState(bool isPush)
{
if (animator.GetBool("Vertigo"))
{
return;
}
animator.SetBool("Push", isPush);
animator.SetLayerWeight(1, isPush?1:0);
}
//punch
public void ChangeAnimationPunchState(bool isPunch)
{
if (animator.GetBool("Vertigo"))
{
return;
}
animator.SetBool("Punch", isPunch);
if (!isPunch||animator.GetFloat("Power") < 1.1f) {
animator.SetLayerWeight(1, 0);
}
else
{
animator.SetLayerWeight(1,1);
}
//animator.SetLayerWeight(1, isPunch ? 1 : 0);
}
////Push
//public void ChangeAnimationPushState(bool isPush)
//{
// if (animator.GetBool("Vertigo"))
// {
// return;
// }
// animator.SetBool("Push", isPush);
// animator.SetLayerWeight(1, isPush?1:0);
//}
////punch
//public void ChangeAnimationPunchState(bool isPunch)
//{
// if (animator.GetBool("Vertigo"))
// {
// return;
// }
// animator.SetBool("Punch", isPunch);
// if (!isPunch||animator.GetFloat("Power") < 1.1f) {
// animator.SetLayerWeight(1, 0);
// }
// else
// {
// animator.SetLayerWeight(1,1);
// }
// //animator.SetLayerWeight(1, isPunch ? 1 : 0);
//}
}
......@@ -46,10 +46,13 @@ public class PlayerMove : MonoBehaviour
//眩晕
[HideInInspector]
public float vertigoTime = 0.0f;
private AnimationManager animationManager;
// Start is called before the first frame update
void Start()
{
......@@ -60,6 +63,7 @@ public class PlayerMove : MonoBehaviour
//获取animator组件
animator=GetComponentInChildren<Animator>();
characterController = GetComponentInChildren<CharacterController>();
animationManager = GetComponentInChildren<AnimationManager>();
}
private void OnTriggerEnter(Collider other)
......@@ -280,64 +284,39 @@ public class PlayerMove : MonoBehaviour
if ( !BattleCtrl.instance.IsScoreSettlementStatus)
{
if (vertigoTime >0)
{
//眩晕
vertigoTime -= Time.deltaTime;
vertigoEffect.gameObject.SetActive(true);
animator.SetBool("Vertigo", true);
animator.SetBool("Push", false);
animator.SetBool("Punch", false);
//AnimationManager(AnimationState.Vertigo);//眩晕动画
animationManager.ChangeAnimatorState(AnimationState.Vertigo);
}
else
{
vertigoEffect.gameObject.SetActive(false);
vertigoTime = 0;
animator.SetBool("Vertigo", false);
//animator.SetBool("Vertigo", false);//解除眩晕动画
animationManager.VertigoToAwake();
UpdateJoystick();
}
}
else
//调用一次性方法
if (targetWall == null)
{
//游戏已经结束但可以继续滑行
//print("游戏已经结束但可以继续滑行"); //Move((transform.forward * MoveSpeed + new Vector3(0, _vertSpeed, 0)) * Time.deltaTime + (new Vector3(xDelta, 0, 0)));
if (characterController.velocity.z >= 0)
{
//print("滑行");
//characterController.SimpleMove(new Vector3(0, 0, characterController.velocity.z - deceleration * Time.deltaTime));
}
else
{
//print("滑行结束");
BattleCtrl.instance.ExitScoreSettlementStatus();
//获取滑行倍率
Physics.Raycast(transform.position, -transform.up, out hit, 30);
//print(hit.collider.name);
if (hit.collider.gameObject.GetComponent<TextMeshPro>() == null)
{
BattleCtrl.instance.Magnification = 1;
}
else
{
string magnificationStr = hit.collider.gameObject.GetComponent<TextMeshPro>().text.Replace("x", "");
BattleCtrl.instance.Magnification = Convert.ToInt32(magnificationStr);
}
BattleCtrl.instance.targetScore = BattleCtrl.instance.Score * BattleCtrl.instance.Magnification;
}
animationManager.NotPush();
}
//推墙
if (targetWall == null)
if (GameObject.FindGameObjectWithTag("Boss")==null)
{
//游戏失败
animator.SetBool("Push", false);
animationManager.ResetPunch();
}
}
//摇杆控制
void UpdateJoystick()
{
......@@ -386,6 +365,8 @@ public class PlayerMove : MonoBehaviour
animator.SetBool("Grounded", Grounded);
}
......
......@@ -4,7 +4,7 @@ using UnityEngine;
public class Wall : MonoBehaviour
{
public AttackTrigger target;
//public AttackTrigger target;
public ParticleSystem ps;
void Start()
......@@ -19,7 +19,7 @@ public class Wall : MonoBehaviour
particleSystem.gameObject.AddComponent<DestroyMySel>();
particleSystem.transform.localScale = new Vector3(2,2,2);
particleSystem.Play();
target.ChangeAnimationPushState(false);
//target.ChangeAnimationPushState(false);
Destroy(gameObject);
}
}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCharacterC : MonoBehaviour
{
private CharacterController characterController;
public float xDelta = 0;
public float yDelta = 0;
public float zDelta = 0;
// Start is called before the first frame update
void Start()
{
characterController = GetComponentInChildren<CharacterController>();
}
// Update is called once per frame
void Update()
{
characterController.Move(new Vector3(xDelta,yDelta,zDelta)*Time.deltaTime);
print("isGround:"+characterController.isGrounded);
}
}
fileFormatVersion: 2
guid: fe9b447ccc15eb24cbbc1299f715233c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 06290052a46fa09459875164e73c248f
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment