我对Unity非常陌生,昨天刚刚在Unity3d的学习页面上的滚球示例之后完成。平滑相机跟随基于Voxel球体
为了实践我学到的东西,我想尝试用我自己的艺术创造类似的东西,让游戏变得不同。我一直在玩Voxel Art,我正在使用MagicaVoxel来创建我的资产。我创造了墙壁,地面等。一切都很好。
然后来了球员对象,球体。我使用magicaVoxel创建了一个尽可能接近球体的球体,并且它的滚动性能很好。但是,使用脚本使相机跟随物体时会遇到问题。
如果我不限制Y轴,那么我会弹跳,并且尽可能的在X轴和Z轴上得到一种平坦轮胎效应。基本上相机不顺利它反弹,停止走等...
我试图让对撞机大于球体,甚至使用对撞机的位置与对象本身。我也尝试把代码放在Update/FixedUpdate/LateUpdate中。什么是解决或解决这样的问题的正确方法?这里是我下面的脚本:
相机控制器:
public class CamController : MonoBehaviour {
public GameObject player;
private Vector3 offset;
void Start()
{
// Get the distance between the player ball and camera.
offset = this.transform.position - player.transform.position;
}
void LateUpdate()
{
this.transform.position = player.transform.position + offset;
}
}
播放器控制器:
public class PlayerController : MonoBehaviour {
public float _speed;
void FixedUpdate()
{
// Get input from keyboard.
float _hoz = Input.GetAxis("Horizontal");
float _ver = Input.GetAxis("Vertical");
// Create a vector3 based on input from keyboard.
Vector3 _move = new Vector3(_hoz, 0.0f, _ver);
// Apply force to the voxel ball
this.GetComponent<Rigidbody>().AddForce(_move * _speed);
}
}
感谢提前任何帮助。
https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html – 2016-09-15 06:34:42