Ejemplo n.º 1
0
    public virtual void Move()
    {
        if (_TriggerStayTSCollisions.Count > 0)
        {
            //此算法,不能解决两个阻碍墙夹角少于90的问题
            TSVector AngleOnNormal = Angle;// new TSVector(Angle.x, FP.Zero, Angle.z);
            foreach (KeyValuePair <int, TSCollision> item in _TriggerStayTSCollisions)
            {
                //pengzhuanweizhi.transform.position = item.Value.contacts[0].point.ToVector();
                //pengzhuanfaxiangliang1.transform.position = item.Value.contacts[0].point.ToVector();
                //pengzhuanfaxiangliang2.transform.position = AllTSTransform.position.ToVector();
                //pengzhuanfaxiangliang3.transform.position = item.Value.contacts[0].point.ToVector();
                //pengzhuanfaxiangliang1.transform.rotation = TSQuaternion.LookRotation(item.Value.contacts[0].normal).ToQuaternion();
                TSVector diff = item.Value.contacts[0].point - AllTSTransform.position;
                //pengzhuanfaxiangliang2.transform.rotation = TSQuaternion.LookRotation(diff).ToQuaternion();
                //pengzhuanfaxiangliang2.transform.rotation = TSQuaternion.LookRotation(Angle).ToQuaternion();
                //pengzhuanfaxiangliang1.transform.rotation = TSQuaternion.LookRotation(new TSVector(-z, FP.Zero, x)).ToQuaternion();
                //pengzhuanfaxiangliang3.transform.rotation = TSQuaternion.LookRotation(AngleOnNormal).ToQuaternion();
                FP AngleAndDiff = TSVector2.Angle(new TSVector2(AngleOnNormal.x, AngleOnNormal.z), new TSVector2(diff.x, diff.z));
                //Debug.LogErrorFormat("夹角度{0},控制轮盘的投影{1},控制轮盘{2},Actor与碰撞点向量{3}", AngleAndDiff, AngleOnNormal.ToString(), Angle.ToString(), diff.ToString());
                //Debug.LogErrorFormat("Actor====>Angle==>{0}", TSVector2.Angle(new TSVector2(Angle.x, Angle.z), new TSVector2(item.Value.contacts[0].normal.x, item.Value.contacts[0].normal.z)));
                if (AngleAndDiff < 90)
                {
                    AngleOnNormal = TSVector.Project(AngleOnNormal, new TSVector(-item.Value.contacts[0].normal.z, FP.Zero, item.Value.contacts[0].normal.x));
                    //TmpAngle = AngleOnNormal;//让控制轮盘方向变成修正后的方向AngleOnNormal
                }
                else
                {
                    //AngleOnNormal = TmpAngle;//new TSVector(Angle.x, FP.Zero, Angle.z);
                }

                /***
                 * if (diff.magnitude < (FP)0.9) {
                 *  TSVector _addTranslation3 = new TSVector(0, 0, 0);
                 *  if (diff.x < FP.Zero) _addTranslation3.x -= 1;
                 *  else if (diff.x > FP.Zero) _addTranslation3.x += 1;
                 *  if (diff.z < FP.Zero) _addTranslation3.z -= 1;
                 *  else if (diff.z > FP.Zero) _addTranslation3.z += 1;
                 *  _addTranslation3 = _addTranslation3.normalized;
                 *  AllTSTransform.position = new TSVector(item.Value.contacts[0].point.x, 0, item.Value.contacts[0].point.z) - _addTranslation3;
                 *  Debug.LogErrorFormat("修复=================================>{0},{1}", diff.ToString(), _addTranslation3.ToString());
                 * }
                 ***/
            }
            AllTSTransform.Translate(AngleOnNormal * Speed);
        }
        else
        {
            AllTSTransform.Translate(Angle * Speed);
        }
    }
Ejemplo n.º 2
0
    void MoveCallBack(Vector2 tVec2)
    {
        TSVector2 mTSVector2 = new TSVector2((FP)(tVec2.x - 0.001f), (FP)(tVec2.y - 0.001f)).normalized;//这里减0.001f是因为这里精度有问题,会传来一个极其微小大于1的浮点数,后面使用时候导致FP Acos()中算出来的1值(4294967297)大于FP.ONE值(4294967296)
        FP        anglenew   = TSVector2.Angle(mTSVector2, TSVector2.up);
        FP        angle      = TSQuaternion.Angle(AllTSTransform.rotation, RotateTSTransform.rotation);

        //FP iTanDeg = TSMath.Atan2((FP)tVec2.y, (FP)tVec2.x) * FP.Rad2Deg;
        //Debug.LogErrorFormat("MoveCallBack===12=======>{0},{1},{2},{3},iTanDeg={4}", mTSVector2.x, mTSVector2.y, mTSVector2.ToString(), anglenew, iTanDeg);
        if (mTSVector2.x < 0 && (360 - anglenew) < 183)
        {
            anglenew = 360 - anglenew;                                             //这里让他们夹角在0-183范围内,刚好与下面的0-180错开3(灵敏度5的一半),这样就少算了一次RotateTransform.rotation.eulerAngles的值
        }
        //if (mTSVector2.y < 0) anglenew = 360 - anglenew;
        //if (RotateTransform.rotation.eulerAngles.x < 0) angle = 360 - angle;
        //Debug.LogErrorFormat("MoveCallBack==2====>{0},{1},ToString={2}", anglenew, angle, RotateTSTransform.rotation.ToString());
        if (TSMath.Abs(angle - anglenew) > 5)
        {
            int x = FP.ToInt(mTSVector2.x * 1000);
            int y = FP.ToInt(mTSVector2.y * 1000);
            //Debug.LogErrorFormat("MoveCallBack=3==>{0},{1}", x, y);
            _UdpSendManager.SendChangeAngle(x, y);
        }
    }
    private void OnKickOccurred(tnKickable i_Target)
    {
        if (m_Results == null)
        {
            return;
        }

        if (i_Target == null)
        {
            return;
        }

        if (i_Target.CompareTag(Tags.s_Ball))
        {
            m_Results.shots = m_Results.shots + 1;

            if (m_OpponentGoal != null)
            {
                TSVector2 topPostPosition    = m_OpponentGoal.topPostPosition;
                TSVector2 bottomPostPosition = m_OpponentGoal.bottomPostPosition;

                TSVector2 currentPosition = tsTransform2D.position;

                TSVector2 topPostDirection = topPostPosition - currentPosition;
                topPostDirection.Normalize();

                TSVector2 bottomPostDirection = bottomPostPosition - currentPosition;
                bottomPostDirection.Normalize();

                TSVector2 targetPosition = i_Target.tsTransform2D.position;

                TSVector2 targetDirection = targetPosition - currentPosition;
                targetDirection.Normalize();

                TSVector2 goalPosition = m_OpponentGoal.tsTransform2D.position;

                TSVector2 goalDirection = goalPosition - currentPosition;
                goalDirection.Normalize();

                FP dot = TSVector2.Dot(targetDirection, goalDirection);

                if (dot > 0f)
                {
                    FP angleA = TSVector2.Angle(topPostDirection, TSVector2.up);
                    FP angleB = TSVector2.Angle(bottomPostDirection, TSVector2.up);

                    FP shotAngle = TSVector2.Angle(targetDirection, TSVector2.up);

                    if (shotAngle > angleA && shotAngle < angleB)
                    {
                        m_Results.shotsOnTarget = m_Results.shotsOnTarget + 1;
                    }
                }
            }
        }
        else
        {
            if (i_Target.CompareTag(Tags.s_Character))
            {
                m_Results.tackles = m_Results.tackles + 1;
            }
        }
    }