gpt4 book ai didi

unity3d - 如何在unity3D中平滑移动Camera?

转载 作者:行者123 更新时间:2023-12-04 05:48:27 24 4
gpt4 key购买 nike

当我想将Camera从原点移动到目标位置时,它看起来很僵硬。那么如果它可以根据偏移设置移动速度,怎么办?

最佳答案

关于这个问题有一个很好的教程,通常在开头描述of all tutorials在统一网站上。 Survival Shooter Tutorial里面有解释如何在移动时使相机平滑地移动到目标位置。

这是移动相机的代码。创建一个脚本,将其添加到相机并将要移动到的 GameObject 添加到脚本占位符中。它会像脚本中的设置一样自动保存 Transform 组件。 (在我的例子中,它是生存射击游戏教程的玩家):

public class CameraFollow : MonoBehaviour
{
// The position that that camera will be following.
public Transform target;
// The speed with which the camera will be following.
public float smoothing = 5f;

// The initial offset from the target.
Vector3 offset;

void Start ()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}

void FixedUpdate ()
{
// Create a postion the camera is aiming for based on
// the offset from the target.
Vector3 targetCamPos = target.position + offset;

// Smoothly interpolate between the camera's current
// position and it's target position.
transform.position = Vector3.Lerp (transform.position,
targetCamPos,
smoothing * Time.deltaTime);
}
}

关于unity3d - 如何在unity3D中平滑移动Camera?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com