【问题标题】:Make the CC Collider follow the camera (UNITY)使 CC Collider 跟随相机 (UNITY)
【发布时间】:2022-01-23 03:55:57
【问题描述】:

所以我制作了一个脚本,理论上应该让角色控制器的碰撞器跟随玩家相机。这是脚本:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;

public class CCCameraFollower : MonoBehaviour
{

    public GameObject Camera;
    public CharacterController character;
    // Start is called before the first frame update
    void Start()
    {
        character = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void LateUpdate()
    {
        character.center = Camera.transform.position;
    }
}

当我尝试它时,这很好/可以,但是一旦我在我的 Climber 脚本中输入Climb()

    void Climb()
    {
        InputDevices.GetDeviceAtXRNode(climbingHand.controllerNode)
            .TryGetFeatureValue(CommonUsages.deviceVelocity, out Vector3 velocity);

        character.Move(transform.rotation * -velocity * Time.fixedDeltaTime);
        cachedVelocity = -velocity;
        Debug.Log(cachedVelocity);
    }

当这是 Climb() 运行时,会发生这种情况: Image that Shows The Issue

我看不出发生这种情况的原因,也许它非常明显。我不知道......无论如何,我的问题是:“我如何让 CC 的 Collider 跟随玩家相机?”。

【问题讨论】:

    标签: c# unity3d virtual-reality


    【解决方案1】:

    在 CCCameraFollower.LateUpdate() 方法中,您实际上是在移动角色控制器的中心,而不是相机的位置。更改为这个,它可能会按你的意愿工作。

    void LateUpdate()
    {
        Camera.transform.position = character.center;
    }
    

    【讨论】:

    • 嘿,这种工作。基本上,在VR头显本身中是可以的,但是在PC上的场景中,相机本身并没有移动,我不知道如何将图像添加到imgur所以你很抱歉。
    • 另外,当在 IRL 中移动时,对撞机也不会改变位置,而在相机中会改变
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-21
    • 1970-01-01
    • 2021-01-12
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    相关资源
    最近更新 更多