【发布时间】:2017-04-30 17:41:49
【问题描述】:
我现在正在为此苦苦挣扎一段时间。我有 GameObject,它是一个球体,它是我在 3d 地形上的玩家。我有一个始终与玩家保持固定距离的相机,使用以下脚本跟随它:
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start () {
offset = transform.position - player.transform.position;
}
void LateUpdate () {
transform.position = player.transform.position + offset;
}
到目前为止一切顺利。但是我真正想要的是相机随着玩家旋转,所以它总是看着球体移动的方向,但总是在玩家身后保持相同的固定距离,这样玩家在相机视图中总是可见的.
有很多可用的脚本,但是到目前为止我所看到的一次的问题是相机确实会随着玩家旋转,但是因为玩家实际上是一个滚动的球体,所以相机视图正在滚动和转动好吧。
到目前为止我找到的最好的脚本如下,但是这个和其他的有同样的问题,相机随着播放器滚动。
public Transform target;
public float distance = 3.0f;
public float height = 3.0f;
public float damping = 5.0f;
public bool smoothRotation = true;
public bool followBehind = true;
public float rotationDamping = 10.0f;
void Update () {
Vector3 wantedPosition;
if(followBehind)
wantedPosition = target.TransformPoint(0, height, -distance);
else
wantedPosition = target.TransformPoint(0, height, distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
if (smoothRotation) {
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
//Quaternion ownRotation = Quaternion.RotateTowards;
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}
else transform.LookAt (target, target.up);
}
谁能帮我解决这个问题?
【问题讨论】:
-
你的相机
GameObject是球体的孩子吗? -
没有。我试过了,但结果是一样的
-
您是否尝试过删除
smoothRotation函数(在您的情况下为if语句)? -
是的,也有结果是相机仍在旋转并且还丢失了播放器对象