public behaviac.EBTStatus BackHome()
    {
///<<< BEGIN WRITING YOUR CODE BackHome
        if (ShowLog)
        {
            Debug.Log("BackHome==>");
        }
        TSVector Angle    = (mBackPosition - AllTSTransform.position).normalized;
        FP       Distance = (mBackPosition - AllTSTransform.position).magnitude;

        if (Distance <= 1)
        {
            AllTSTransform.position = new TSVector(mBackPosition.x, mBackPosition.y, mBackPosition.z);
            _TargetEnemyActor       = null;
            mEnemyActorDict         = new Dictionary <int, Actor>();   //清空
            mActorAttr.Hp           = mActorAttr.HpMax;
            return(behaviac.EBTStatus.BT_SUCCESS);
        }
        else
        {
            AllTSTransform.Translate(Angle * Speed * 2);
            RotateTSTransform.rotation = TSQuaternion.LookRotation(Angle);
            mActorAttr.Hp += 1;
        }
        return(behaviac.EBTStatus.BT_RUNNING);
///<<< END WRITING YOUR CODE
    }
    public void Pursuit()
    {
///<<< BEGIN WRITING YOUR CODE Pursuit
        if (ShowLog)
        {
            Debug.Log("Pursuit==>");
        }
        TSVector Angle = (_TargetEnemyActor.AllTSTransform.position - AllTSTransform.position).normalized;

        AllTSTransform.Translate(Angle * Speed);
        RotateTSTransform.rotation = TSQuaternion.LookRotation(Angle);
///<<< END WRITING YOUR CODE
    }
Example #3
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);
        }
    }
Example #4
0
    //================================技能实现效果相关===========================================
    public override void Skill_1(params object[] param)      //闪现
    {
        TSVector rayOrigin    = AllTSTransform.position;
        TSVector rayDirection = this.Angle;
        FP       maxDistance  = Speed * 50;
        //int layerMask = UnityEngine.Physics.DefaultRaycastLayers;
        int          layerMask = LayerMask.GetMask("Wall");
        bool         bHit      = false;//= TSPhysics.Raycast(rayOrigin, rayDirection, hit, maxDistance, layerMask);
        TSRay        ray       = new TSRay(rayOrigin, rayDirection);
        TSRaycastHit hit       = PhysicsWorldManager.instance.Raycast(ray, maxDistance, layerMask);

        if (hit != null)
        {
            if (hit.distance <= maxDistance)
            {
                bHit = true;
            }
        }
        //Debug.LogErrorFormat("闪现1,起点{0},方向{1},距离{2},是否{3}", rayOrigin.ToString(), rayDirection.ToString(), maxDistance.ToString(), bHit);
        if (!bHit)
        {
            AllTSTransform.Translate(Angle * maxDistance);
            return;
        }
        //TrueSyncManager.SyncedInstantiate(WillUsedPrefabs[0], hit.point, RotateTSTransform.rotation);
        //Debug.LogFormat("射线碰撞点1,point={0},transform={1},法向量normal={2},collider={3},distance={4}", hit.point.ToString(), hit.transform.ToString(), hit.normal.ToString(), hit.collider.ToString(), hit.distance.ToString());
        //开始检查反方向的碰撞点法向量是(0,0,0),说明在在内部
        TSVector     rayOrigin2    = rayOrigin + (Angle * maxDistance); //rayOrigin+maxDistance的目标坐标
        TSVector     rayDirection2 = TSVector.Negate(this.Angle);       //逆向量的方向
        TSRay        ray2          = new TSRay(rayOrigin2, rayDirection2);
        TSRaycastHit hit2          = PhysicsWorldManager.instance.Raycast(ray2, maxDistance, layerMask);
        bool         bHit2         = false;

        if (hit2 != null)
        {
            if (hit2.distance <= maxDistance)
            {
                bHit2 = true;
            }
        }
        //Debug.LogErrorFormat("闪现2,起点{0},方向{1},距离{2},是否{3}", rayOrigin2.ToString(), rayDirection2.ToString(), maxDistance.ToString(), bHit2);
        if (bHit2)
        {
            TrueSyncManager.SyncedInstantiate(WillUsedPrefabs[0], hit2.point, RotateTSTransform.rotation);
            //Debug.LogFormat("射线碰撞点2,point={0},transform={1},法向量normal={2},collider={3},distance={4}", hit2.point.ToString(), hit2.transform.ToString(), hit2.normal.ToString(), hit2.collider.ToString(), hit2.distance.ToString());
            if (!hit2.normal.IsNearlyZero())
            {
                if (hit2.distance > (FP)1f)
                {
                    AllTSTransform.Translate(Angle * maxDistance);
                    //Debug.LogErrorFormat("超距离{0},", hit2.distance.ToString());
                }
                else
                {
                    AllTSTransform.Translate(Angle * maxDistance);
                    AllTSTransform.Translate(hit2.normal * ((FP)1f - hit2.distance));                    //修正一个人物碰撞半径:碰撞法向量的垂直向量
                    //Debug.LogErrorFormat("碰撞法向量的垂直向量{0},",(new TSVector(-hit2.normal.z, FP.Zero, hit2.normal.x) * (FP)1f).ToString());
                }
                return;
            }
            else
            {
                //Debug.LogErrorFormat("IsNearlyZero=={0},{1},", hit2.normal.IsNearlyZero(), hit2.normal.sqrMagnitude);
            }
        }
        AllTSTransform.position = hit.point;
        AllTSTransform.Translate(hit.normal * (FP)1f);        //修正一个人物碰撞半径:碰撞法向量的垂直向量
    }