Example #1
0
        private bool CalculateNextPosition(TSVector curPosition, FP deltaTime, out TSVector position, out TSVector forward)
        {
            position = TSVector.zero;
            forward  = m_sCurForward;
            TSVector deltaPosition = m_sNextPosition - curPosition;

            if (!deltaPosition.IsZero())
            {
                TSVector deltaForward = deltaPosition.normalized;
                TSVector offset       = deltaForward * m_sSpeed * deltaTime;
                if (deltaPosition.sqrMagnitude > offset.sqrMagnitude)
                {
                    position = curPosition + offset;
                }
                else
                {
                    position = m_sNextPosition;
                    if (!DequeuePoint(position, out forward))
                    {
                        forward = m_sCurForward;
                        return(false);
                    }
                }
            }
            else
            {
                position = m_sNextPosition;
                if (!DequeuePoint(position, out forward))
                {
                    forward = m_sCurForward;
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
 public bool StartRotateBySpeed(TSVector startForward, TSVector targetForward, FP angleSpeed)
 {
     if (startForward.IsZero() || targetForward.IsZero())
     {
         return(false);
     }
     startForward.Normalize();
     m_sCurForward = m_sStartForward = startForward;
     targetForward.Normalize();
     m_sTargetForward = targetForward;
     if ((startForward - targetForward).IsZero())
     {
         return(false);
     }
     m_sSpeed          = angleSpeed / 360;
     m_sStartRotation  = TSQuaternion.identity;
     m_sTargetRotation = TSQuaternion.FromToRotation(m_sStartForward, m_sTargetForward);
     m_nRotating       = true;
     m_sLerp           = 0;
     if (null != OnStartRotate)
     {
         OnStartRotate(m_sCurForward, m_sCurForward);
     }
     return(true);
 }
 public override void OnSyncedUpdate()
 {
     if (Angle.IsZero())
     {
         return;
     }
     AllTSTransform.Translate(Angle * Speed);
     AllTSTransform.OnUpdate();
     RotateTSTransform.OnUpdate();
     //Debug.LogErrorFormat("houyiBullet====>{0},{1},{2}",ownerIndex, Angle, RotateTSTransform.rotation.eulerAngles);
 }
Example #4
0
        /// <summary>
        /// Applies an impulse on the center of the body. Changing
        /// linear velocity.
        /// </summary>
        /// <param name="impulse">Impulse direction and magnitude.</param>
        public void ApplyImpulse(TSVector impulse)
        {
            if (this.isStatic || impulse.IsZero())
            {
                return;
            }
            //UnityEngine.Debug.Log($"ApplyImpulse {impulse}");
            TSVector temp;

            TSVector.Multiply(impulse, inverseMass, out temp);
            TSVector.Add(linearVelocity, temp, out linearVelocity);
        }
Example #5
0
        /// <summary>
        /// Applies an impulse on the specific position. Changing linear
        /// and angular velocity.
        /// </summary>
        /// <param name="impulse">Impulse direction and magnitude.</param>
        /// <param name="relativePosition">The position where the impulse gets applied
        /// in Body coordinate frame.</param>
        public void ApplyImpulse(TSVector impulse, TSVector relativePosition)
        {
            if (this.isStatic || impulse.IsZero())
            {
                return;
            }

            TSVector temp;

            TSVector.Multiply(impulse, inverseMass, out temp);
            TSVector.Add(linearVelocity, temp, out linearVelocity);

            TSVector.Cross(relativePosition, impulse, out temp);
            TSVector.Transform(temp, invInertiaWorld, out temp);
            TSVector.Add(angularVelocity, temp, out angularVelocity);
        }
Example #6
0
        public void StartMove(TSVector startPosition, List <TSVector> lstPosition)
        {
            TSVector forward = m_sCurForward;

            if (lstPosition.Count > 0)
            {
                forward = lstPosition[0] - startPosition;
            }
            if (!forward.IsZero())
            {
                forward.Normalize();
            }
            SetForward(forward);
            SetPosition(startPosition);
            List <Vector3> lst = GameInTool.TSVectorToLstUnityVector3(lstPosition);

            m_cLerpView.StartMove(transform.position, lst);
        }
Example #7
0
 private bool DequeuePoint(TSVector curPosition, out TSVector forward)
 {
     forward = TSVector.forward;
     if (m_queuePath.Count > 0)
     {
         while (m_queuePath.Count > 0)
         {
             m_sNextPosition = m_queuePath.Dequeue();
             forward         = m_sNextPosition - curPosition;
             if (!forward.IsZero())
             {
                 forward.Normalize();
                 return(true);
             }
         }
     }
     return(false);
 }
        protected override void OnSelectChild(AgentObjectBlackBoard blackBoard, List <AgentObject> lst, ref List <SelectAgentObjInfo> result)
        {
            if (lst.Count == 0)
            {
                return;
            }
            AgentObject host         = blackBoard.host;
            TSVector    lastPosition = host.lastPosition;
            TSVector    lastForward  = host.lastForward;

            if (!string.IsNullOrEmpty(m_cLastPosToCurPosData.hangPoint))
            {
                blackBoard.host.GetHangPoint(m_cLastPosToCurPosData.hangPoint, host.lastPosition, host.lastForward, out lastPosition, out lastForward);
            }
            TSVector curPosition = host.curPosition;
            TSVector curForward  = host.curForward;

            if (!string.IsNullOrEmpty(m_cLastPosToCurPosData.hangPoint))
            {
                blackBoard.host.GetHangPoint(m_cLastPosToCurPosData.hangPoint, host.curPosition, host.curForward, out curPosition, out curForward);
            }
            //检测lastPosition到curPosition这条之间碰撞到的代理
            for (int i = 0; i < lst.Count; i++)
            {
                var agentObj = lst[i];
                if (agentObj.gameCollider != null)
                {
                    TSVector hitPoint;
                    if (agentObj.gameCollider.CheckLine(lastPosition, curPosition - lastPosition, out hitPoint))
                    {
                        SelectAgentObjInfo info = new SelectAgentObjInfo();
                        info.agentObj = agentObj;
                        info.hitPoint = hitPoint;
                        TSVector direct = agentObj.gameCollider.center - curPosition;;
                        if (direct.IsZero())
                        {
                            direct = curForward;
                        }
                        info.hitDirect = direct;
                        result.Add(info);
                    }
                }
            }
        }