尝试以统一3D冻结相机位置

问题描述

我试图使相机以统一的3D跟随玩家,我将相机固定在玩家身上,但是它也会随他一起旋转,因为他是球,我不希望发生这种情况,因此我在相机上添加了刚体曾经工作过一次IDK的方式,但是由于僵硬的任何帮助,它都停止了跟踪他??

解决方法

因此,您已经将相机变成了播放器的孩子?如果是这样,相机将继承播放器上的所有变换,这绝对不是您想要的。您可以按照此视频来学习相机跟踪脚本。 https://www.youtube.com/watch?v=MFQhpwc6cKE

您几乎不需要在相机上放置刚体,因此可以将其移除。

,

子对象始终继承父对象的变换,如Christopher所说。因此,如果球在世界范围内滚动,您的相机也会旋转(在这种情况下,由RigidBody /物理控制)。

为了使摄像机跟随场景中的任何对象,可以为摄像机使用单独的GameObject,该对象跟随由简单脚本控制的玩家对象。 -例如以下内容(来自Unity documentation的修改示例):

using UnityEngine;

public class SmoothFollow : MonoBehaviour
{
    public Transform target;
    public float smoothTime = 0.3f;
    public Vector3 offset = new Vector3(0.0f,5.0f,-10.0f);
    private Vector3 velocity = Vector3.zero;

    void Update()
    {
        // Define a target position above and behind the target transform
        Vector3 targetPosition = target.TransformPoint(offset);

        // Smoothly move the camera towards that target position
        transform.position = Vector3.SmoothDamp(transform.position,targetPosition,ref velocity,smoothTime);
        
        // Make the camera point towards the target
        transform.LookAt(target);
    }
}

screenshot of script component in Unity Inspector window

这是一个非常基本的问题,并且已经被回答过很多次了。您只需在网上搜索就可以轻松找到许多类似的示例。-帖子标题与该问题确实不符。重要的是找到正确的单词和提示,以使该站点正常运行(明确的技术问题->明确的答案)。