Example #1
0
    private void Update()
    {
        transform.localRotation = TSQuaternion.Euler(TSVector.up * this.wheelAngle).ToQuaternion();
        // tsTransform.localRotation = TSQuaternion.Euler(TSVector.up * this.wheelAngle);

        Debug.DrawRay(transform.position, -transform.up * (springLength.AsFloat() + wheelRadius), Color.red);
    }
    /// <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;
        }
    }