/// <summary>
    /// Turn the ship to look at a target.
    /// </summary>
    /// <param name="targetin"></param>
    void Look(TSVector targetin)
    {
        TSVector     targetDir       = localtarget - transformts.position;
        TSQuaternion directiontarget = TSQuaternion.LookRotation(targetDir);
        TSQuaternion outputrot       = TSQuaternion.Slerp(transformts.rotation, directiontarget, TrueSyncManager.DeltaTime * turnspeed);

        if (TSQuaternion.Angle(outputrot, lastquaternion) < (TrueSyncManager.DeltaTime * turnspeed) / 2)
        {
            transformts.rotation = outputrot;
        }
        lastquaternion = outputrot;
    }
示例#2
0
        public bool StartRotate(TSVector startForward, TSVector targetForward, FP time)
        {
            var rotation   = TSQuaternion.FromToRotation(m_sStartForward, m_sTargetForward);
            FP  angle      = TSQuaternion.Angle(TSQuaternion.identity, rotation);
            FP  angleSpeed = FP.MaxValue;

            if (time > 0)
            {
                angleSpeed = angle / time;
            }
            return(StartRotateBySpeed(startForward, targetForward, angleSpeed));
        }
    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);
        }
    }