【发布时间】:2020-08-28 23:50:48
【问题描述】:
我试图让相机在统一的 3D 中跟随玩家我将相机连接到玩家但它也随着他旋转因为他是一个球我不希望这种情况发生我在相机上添加了一个刚体曾经 IDK 工作过一次,但由于刚体的帮助,它停止了跟随他??
【问题讨论】:
标签: c# unity3d camera rotation game-development
我试图让相机在统一的 3D 中跟随玩家我将相机连接到玩家但它也随着他旋转因为他是一个球我不希望这种情况发生我在相机上添加了一个刚体曾经 IDK 工作过一次,但由于刚体的帮助,它停止了跟随他??
【问题讨论】:
标签: c# unity3d camera rotation game-development
所以你已经让你的相机成为你的玩家的孩子了?如果是这样,相机将继承您播放器的所有转换,这绝对不是您想要的。您可以观看此视频来学习相机跟随脚本。 https://www.youtube.com/watch?v=MFQhpwc6cKE
而且您几乎不需要在相机上放置刚体,因此您可以移除它。
【讨论】:
正如 Christopher 已经说过的,子对象总是继承父对象的变换。因此,如果球在世界上滚动,您的相机也会旋转(在这种情况下由刚体/物理控制)。
为了使相机跟随场景中的任何对象,您可以为相机使用单独的游戏对象,它跟随由简单脚本控制的玩家对象。 - 例如这样的事情(来自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);
}
}
(这是一个非常基本的问题,之前已经回答过很多次了。你可以通过搜索网络轻松找到许多类似的例子。 - 帖子的标题与问题不匹配。重要的是要找到正确的词语和提示,以保持网站正常运行(明确的技术问题 -> 明确的答案)。)
【讨论】: