float RotateForwardTarget() { Vector3 vForward = new Vector3(CurrentActor.MainObj.transform.forward.x, 0f, CurrentActor.MainObj.transform.forward.z); float fCurForwardAngle = ActorBlendAnim.HorizontalAngle(vForward); float fTargetAngle = ActorBlendAnim.HorizontalAngle(m_targetForward); float fLerp = Mathf.LerpAngle(fCurForwardAngle, fTargetAngle, Time.deltaTime * m_fRotateSpeed); float fInterval = fLerp - fCurForwardAngle; Quaternion quater = Quaternion.Euler(0f, fInterval, 0f); CurrentActor.MainObj.transform.rotation = quater * CurrentActor.MainObj.transform.rotation; return(fInterval); }
public override bool OnUpdate() { if (!CurrentActor.MainRigidBody.isKinematic) { CurrentActor.MainRigidBody.velocity = Vector3.zero; } /////////////////////////////////////////////////////////////////////// if ((CurrentActor.Type == ActorType.enNPC && CurrentActor.CurrentTarget != null) || (CurrentActor.Type == ActorType.enFollow && CurrentActor.CurrentTargetIsDead)) { Vector3 vForward = new Vector3(CurrentActor.MainObj.transform.forward.x, 0f, CurrentActor.MainObj.transform.forward.z); float fCurForwardAngle = ActorBlendAnim.HorizontalAngle(vForward); float fTargetAngle = ActorBlendAnim.HorizontalAngle(m_targetForward); float fInterval = fTargetAngle - fCurForwardAngle; if (Mathf.Abs(fInterval) > 10.0f) { float fLerp = Mathf.LerpAngle(fCurForwardAngle, fTargetAngle, Time.deltaTime * m_rotateSpeed); Quaternion quater = Quaternion.Euler(0f, fLerp - fCurForwardAngle, 0f); CurrentActor.MainObj.transform.rotation = quater * CurrentActor.MainObj.transform.rotation; } } return(false); }
public override bool OnUpdate() { if (CurrentActor.m_isDeposited) {//被托管,同步位置 if (Time.time - m_lastSyncTime > GameSettings.Singleton.m_longConnectTickDuration) { m_lastSyncTime = Time.time; if (CurrentActor.MainPos != m_lastSyncPos) { m_lastSyncPos = CurrentActor.MainPos; IMiniServer.Singleton.SendSyncPosition_C2BS(CurrentActor.ID, CurrentActor.MainPos.x, CurrentActor.MainPos.z); } } } if (CurrentActor.IsCanTeleport) {//瞬移 CurrentActor.SelfTeleport.TeleportOnce(CurrentActor, m_realTargetPos); return(true); } bool isForwardArrived = false; Vector3 curForward = CurrentActor.MainObj.transform.forward; Vector3 v = curForward - m_targetForward; if (v.magnitude > 0.01f) { Vector3 vForward = new Vector3(CurrentActor.MainObj.transform.forward.x, 0f, CurrentActor.MainObj.transform.forward.z); float fCurForwardAngle = ActorBlendAnim.HorizontalAngle(vForward); float fTargetAngle = ActorBlendAnim.HorizontalAngle(m_targetForward); if (null == CurrentActor.mActorBlendAnim || CurrentActor.TargetManager.CurrentTarget == null || CurrentActor.mActorBlendAnim.IsRawRotation())//!锁定目标功能,勿添加其它功能逻辑 added by guo { float fLerp = Mathf.LerpAngle(fCurForwardAngle, fTargetAngle, Time.deltaTime * m_rotateSpeed); float fInterval = fLerp - fCurForwardAngle; Quaternion quater = Quaternion.Euler(0f, fInterval, 0f); CurrentActor.MainObj.transform.rotation = quater * CurrentActor.MainObj.transform.rotation; //旋转角度大于定值则不移动,(防止旋转过程中出现滑步的现象) float maxRotate = GameSettings.Singleton.m_stopMoveMaxRotationValS; if (AnimName == "run") { maxRotate = GameSettings.Singleton.m_stopMoveMaxRotationValR; } if (v.magnitude > maxRotate) { SetVelocity(Vector3.zero, 0f); mStartTime = Time.time; mIsRotating = true; return(false); } } } else { isForwardArrived = true; } if (mIsRotating) { mIsRotating = false; } //!锁定目标功能,勿添加其它功能逻辑 added by guo if (null == CurrentActor.mActorBlendAnim || CurrentActor.TargetManager.CurrentTarget == null) { AnimName = "run"; } //获得真实的移动速度,(解决角色碰到障碍原地跑动的现象) if (Time.time - mStartTime >= 0.2f) { Vector3 distance = CurrentActor.MainPos - mLastMovePos; distance.y = 0; mRealSpeed = distance.magnitude / (Time.time - mStartTime); mStartTime = Time.time; mLastMovePos = CurrentActor.MainPos; } Vector3 d = CurrentActor.MainPos - m_startPos; d.y = 0; Vector3 d2 = TargetPos - m_startPos; d2.y = 0; bool isPosArrived = d.magnitude >= d2.magnitude; if (!isPosArrived) { Vector3 direction = TargetPos - CurrentActor.MainPos; direction.y = 0.0f; direction.Normalize(); m_targetForward = m_isBack ? -direction : direction; Vector3 velocity = direction; float fSpeed = (m_isBack ? CurrentActor.MovebackSpeed : CurrentActor.MoveSpeed); if (AnimName == "backward") { fSpeed = CurrentActor.MovebackSpeed; } SetVelocity(velocity, fSpeed); } if (isPosArrived && (!m_isMakeSureForward || isForwardArrived)) { if (PathNodeList.Count > 0) { TargetPos = PathNodeList[0]; PathNodeList.RemoveAt(0); m_targetForward = TargetPos - CurrentActor.MainPos; m_targetForward.y = 0.0f; m_targetForward.Normalize(); m_isMakeSureForward = false; m_startPos = CurrentActor.MainPos; m_startPos.y = 0.0f; return(false); } return(true); } return(false); }