如何创建 Unity3d Cinemachine 第三人称移动滑动摄像头?

问题描述

我已经创建了一个第三人称自由视角相机以及一个玩家控制器,它从新的输入系统动作地图中获取输入,它来自左摇杆游戏手柄,可以跳跃和观看;感谢youtube教程。当我围绕我的播放器旋转并且播放器朝着相机的方向移动时,相机工作得很好。 在我的手机上构建和播放后,我意识到有一个问题,只要用户不停止按下屏幕,相机就不会停止旋转。我不希望这样,因为它开始变得烦人,用户玩游戏的次数越多。我希望用户按住相机并在他们围绕玩家拖动相机时旋转它(就像在手机游戏 genshin Impact 中一样)。我不知道它的正确术语,但我认为它是一个滑动式第三人称相机。有人能告诉我这是怎么做的吗?

#region Variables
[Serializefield]
private float playerSpeed = 2.0f;
[Serializefield]
private float jumpHeight = 1.0f;
[Serializefield]
private float gravityValue = -9.81f;
[Serializefield]
private float rotationSpeed = 0.1f;
private float rotationVeLocity;

private Transform cameraMain;
private Transform child;
private Player playerInput;
private CharacterController controller;
private Vector3 playerVeLocity;
private bool groundedplayer;
#endregion

#region Main Methods
private void Awake()
{
    playerInput = new Player();
    controller = GetComponent<CharacterController>();
}

private void OnEnable()
{
    playerInput.Enable();
}

private void Ondisable()
{
    playerInput.disable();
}


private void Start()
{
    cameraMain = Camera.main.transform;
    child = transform.GetChild(0).transform;
}

void Update()
{
    groundedplayer = controller.isGrounded;
    if (groundedplayer && playerVeLocity.y < 0)
    {
        playerVeLocity.y = 0f;
    }

    Vector2 movementInput = playerInput.PlayerMain.Move.ReadValue<Vector2>();
    //Vector3 move = new Vector3(movementInput.x,0f,movementInput.y);
    Vector3 move = (cameraMain.forward * movementInput.y + cameraMain.right * movementInput.x);
    move.y = 0f;
    //controller.Move(move * Time.deltaTime * playerSpeed);

    if (move != Vector3.zero)
    {
        float targetAngle = Mathf.atan2(move.x,move.z) * Mathf.Rad2Deg;
        float angle = Mathf.SmoothdampAngle(child.eulerAngles.y,targetAngle,ref rotationVeLocity,rotationSpeed);
        child.rotation = Quaternion.Euler(0f,angle,0f);
        controller.Move(move * Time.deltaTime * playerSpeed);
    }

    // Changes the height position of the player..
    if (playerInput.PlayerMain.Jump.triggered && groundedplayer)
    {
        playerVeLocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
    }

    playerVeLocity.y += gravityValue * Time.deltaTime;
    controller.Move(playerVeLocity * Time.deltaTime);

    
}

以上是最近从youtube教程中学到的播放器控制器代码。下面是游戏手柄的输入动作地图和游戏对象:

enter image description here

enter image description here

解决方法

您可以在新的输入管理器和拖动图像管理输入的 onstick 功能中使用触摸屏(delta)简单地修复它。