我是非常新的团结,并刚刚完成昨天在这里的学习页面在Unity3d的滚轮球的例子。
为了实践我所学到的东西,我想尝试用我自己的艺术重新创造一些类似的东西,让游戏与众不同。我一直在玩Voxel,我正在使用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);
}
}谢谢你提前提供帮助。
发布于 2016-09-15 06:33:26
您可以使用Unity的SmoothFollow脚本来平滑地跟踪摄像机。
下面是如何获得脚本的步骤: 1)资产->>script。2)在出现的对话框中,选择所有脚本,或者只需平滑地跟随一个,然后点击Import按钮。3)现在这个脚本在您的项目中,您可以将它附加到照相机上。
希望这能帮你..。
最好哈迪克。
https://stackoverflow.com/questions/39503725
复制相似问题