Esempio n. 1
0
 public void OnUpdate(FP deltaTime)
 {
     if (m_nRotating)
     {
         m_sLerp += m_sSpeed * deltaTime;
         if (m_sLerp <= FP.One)
         {
             TSQuaternion rotate = TSQuaternion.Lerp(m_sStartRotation, m_sTargetRotation, m_sLerp);
             SetForward(rotate * m_sStartForward);
         }
         else
         {
             SetForward(m_sTargetForward);
             StopRotate();
         }
     }
 }
    /// <summary>
    /// 移动
    /// </summary>
    private void Move()
    {
        if (!(_movX == 0 && _movY == 0))
        {
            bool gotIt = true;
        }

        tsRigidBody.velocity = new TSVector(_movX * speed, 0, _movY * speed);

        // 限制角色移动范围
        tsRigidBody.position = new TSVector(
            TSMath.Clamp(tsRigidBody.position.x, boundary.xMin, boundary.xMax),
            0,
            TSMath.Clamp(tsRigidBody.position.z, boundary.zMin, boundary.zMax)
            );

        // 左右平移时稍微倾斜一下机身(绕 z 轴)
        tsRigidBody.rotation = TSQuaternion.Euler(0, 0, tsRigidBody.velocity.x * -tilt);

        // 旋转方向
        if (_rotX == 0 && _rotY == 0)
        {
            tsTransform.rotation = TSQuaternion.Lerp(tsTransform.rotation, TSQuaternion.identity,
                                                     TrueSyncManager.DeltaTime * rotateSpeed);
        }
        else
        {
            TSVector     joystickKnobPos = new TSVector(_rotX, 0, _rotY);
            TSQuaternion targetRot       = TSQuaternion.LookRotation(joystickKnobPos);
            tsTransform.rotation =
                TSQuaternion.Lerp(tsTransform.rotation, targetRot, TrueSyncManager.DeltaTime * rotateSpeed);
        }

        // 旋转粒子系统
        float r = (float)tsTransform.rotation.eulerAngles.y * Mathf.Deg2Rad;

        if (null != particleSystem1)
        {
            particleSystem1.startRotation = r;
        }
        if (null != particleSystem2)
        {
            particleSystem2.startRotation = r;
        }
    }