//设置初速度 void SetOriginV(float value, float angle) { //浮空追击,但是退出了重力系统 if (!m_isUseGravity) { return; } angle = angle % 360; m_originVelocity.value = value; m_originVelocity.angle = angle; m_originVelocity.vSubY = m_originVelocity.value * Mathf.Sin(m_originVelocity.angle * Mathf.Deg2Rad); m_originVelocity.vSubZ = m_originVelocity.value * Mathf.Cos(m_originVelocity.angle * Mathf.Deg2Rad); m_startMotionTime = Time.time; m_startPos = m_transform.position; //根据角度确定是什么类型运动 if (angle > 0 && angle < 180) { m_gravityMotionType = GravityMotionType.GMT_UP; } else if (angle == 0 || angle == 180) { m_gravityMotionType = GravityMotionType.GMT_PUSH; } else if (angle > 180 && angle < 360) { m_gravityMotionType = GravityMotionType.GMT_DOWN; } //navmesh disenable NavMeshAgent agent = this.GetComponent <NavMeshAgent>(); if (agent != null) { agent.enabled = false; } //设置被击硬直 m_BehitState.isNonControl = true; m_behitParame = m_actor.damageBebitParam; if (m_behitParame == null) { return; //播放声音 // m_BehitState.PlayBehitSound(null, m_behitParame.damgageInfo.attackActor); } m_attackObjForward = m_behitParame.damgageInfo.attackActor.transform.forward; }
public void Init() { m_gameDataBase = CoreEntry.gGameDBMgr; m_actor = this.gameObject.GetComponent <ActorObj>(); m_BehitState = m_actor.behitState; m_isUseGravity = false; m_gravityMotionType = GravityMotionType.GMT_NONE; m_attackObjForward = Vector3.zero; m_startToSkyPos = Vector3.zero; F_ACCE = 0; nCount = 0; m_curRadius = m_actor.GetColliderRadius(); CancelInvoke("AutoCancelStatic"); CancelInvoke("MoveDistanceEnd"); }
// Update is called once per frame void Update() { if (m_actor == null) { return; } if (m_actor.IsDeath()) { m_isUseGravity = false; return; } if (m_actor.IgnoredGravityMotion) { m_isUseGravity = false; return; } if (!m_isUseGravity) { nCount = 0; return; } float diffTime = Time.time - m_startMotionTime; //Y轴当前速度 float vY = m_originVelocity.vSubY - (G_ACCE - F_ACCE) * diffTime; //Y轴位移 float dY = (m_originVelocity.vSubY - 0.5f * (G_ACCE - F_ACCE) * diffTime) * diffTime;; if (m_gravityMotionType == GravityMotionType.GMT_DOWN) { dY = dY * 0.8f; } //Z轴位移 float dZ = m_originVelocity.vSubZ * diffTime; Vector3 movePos = m_attackObjForward.normalized * dZ; //LogMgr.UnityLog("movePos="+movePos.ToString("f4")+", dir="+m_attackObjForward.normalized.ToString("f4")); Vector3 curPos = m_transform.position; Vector3 aimPos = m_startPos + new Vector3(movePos.x, dY, movePos.z); //m_transform.position = m_startPos + new Vector3(movePos.x, dY, movePos.z); bool isOverHeight = false; //float heigth = m_transform.position.y - m_startToSkyPos.y; float heigth = aimPos.y - m_startToSkyPos.y; if (heigth > 5) { //m_transform.position -= new Vector3(0, heigth-5, 0); aimPos -= new Vector3(0, heigth - 2, 0); isOverHeight = true; } //是否碰到墙壁 bool isToWall = false; if (!(Mathf.Abs(m_originVelocity.vSubZ) <= 0.0001)) { Vector3 dir = m_attackObjForward; RaycastHit beHit; if (!BaseTool.instance.CanMoveToPos(curPos, aimPos, m_curRadius) || Physics.Raycast(m_transform.position, dir, out beHit, m_curRadius + 0.5f, m_groundLayerMask)) { //碰到阻挡墙,直接下落 aimPos = curPos; isToWall = true; } } //Vector3 groundPos = BaseTool.instance.GetGroundPoint(m_transform.position); //if (aimPos.y < groundPos.y) //{ // aimPos.y = groundPos.y + 0.01f; //} BaseTool.SetPosition(m_transform, aimPos); //到达最高点, 碰到墙壁 if (isOverHeight || isToWall || (m_gravityMotionType == GravityMotionType.GMT_UP && vY <= 0.0001)) { F_ACCE = 0; if (isOverHeight || isToWall) { SetOriginV(1, 270); } else { //有水平速度,保持不变 if (!(Mathf.Abs(m_originVelocity.vSubZ) <= 0.0001)) { m_gravityMotionType = GravityMotionType.GMT_DOWN; return; } m_actor.StopAll(); SetOriginV(0, 270); m_actor.PlayAction("hit011", false); } } }