为什么Unity 2d中的我的角色/相机口吃?
问题描述:
自从我添加了这个新的相机脚本以来,我的角色(相机试图遵循的角色)在移动时会继续出现口吃。如果我保持这个角色不变,那么它就不会结结巴巴了。为什么Unity 2d中的我的角色/相机口吃?
Here's a video of what I mean.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CameraFollow : MonoBehaviour
{
public Transform lookat;
private bool smooth = true;
private float smoothSpeed = 0.1f;
private Vector3 offset = new Vector3 (0, 0, -6.5f);
void LateUpdate() {
Vector3 desiredPosition = lookat.transform.position + offset;
if (smooth) {
transform.position = Vector3.Lerp (transform.position, desiredPosition, smoothSpeed);
} else {
transform.position = desiredPosition;
}
}
}
请帮助 - 它的驾驶我疯了! 编辑:也忽略底部的错误 - 这是我正在工作的其他东西的一部分。
编辑2:没关系,打开刚体body2d中的插值固定它!谢谢你的帮助!
答
首先,确保更改lookat转换位置的代码在Update()中运行,而不是在LateUpdate()中运行。
如果情况已经如此,或者它没有解决您的问题,您可以尝试运行FixedUpdate()中显示的代码。我不知道为什么,但它应该工作。
答
的studdering不会因造成的更新()功能!
口吃很可能造成由于线性插值()功能,你宁愿使用 SmoothDamp()。
像这样
transform.position = Vector3.SmoothDamp(transform.position, desiredPosition, smoothSpeed);
+0
谢谢,这个工作,但我也发现,在Rigidbody2D中插入插值修复了问题。 – Mooserus
你是如何移动的球员? – Programmer
我的建议是检查Vector3.Lerp的工作方式。我已经解释过一个需要Vector3.Lerp [这里]的问题(https://*.com/questions/42153617/moving-player-in-subway-surf-like-game-using-left-right -swipe/42154529#42154529) – Thalthanas