2
我用相机创建第三个人。相机将与鼠标移动同步移动。我为相机移动创建了脚本,但是当速度很高时,一切都开始动摇了。光滑的相机旋转团结
如何强制相机移动平稳?
Vector3 rotation = new Vector3();
rotation = this.transform.rotation.eulerAngles;
float ver = Input.mousePosition.y - mouse_position.y;
difference_y = difference_y ?? ver;
rotation.y += (float)(((Input.mousePosition.x - mouse_position.x)/one_degree_per_pixel_hor));
rotation.x += (float)((-(Input.mousePosition.y - mouse_position.y)/one_degree_per_pixel_ver));
rotation.z = 0;
if (difference_y != 0) {
// Forward tilt
if (difference_y < 0) {
if (rotation.x > max_slope_forward && rotation.x < max_slope_back) rotation.x = max_slope_forward;
}
// Back tilt
else {
if (rotation.x < max_slope_back && rotation.x > max_slope_forward && rotation.x != max_slope_forward) rotation.x = max_slope_back;
}
}
difference_y = ver;
this.transform.Rotate(new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0),Time.deltaTime*SpeedRotation);
rotation = this.transform.rotation.eulerAngles;
rotation.z = 0;
this.transform.rotation = Quaternion.Euler(rotation);
mouse_position = Input.mousePosition;
看看:http://docs.unity3d.com/ScriptReference/Vector3.Lerp。 html和http://docs.unity3d.com/ScriptReference/Mathf.Lerp.html和https://unity3d.com/learn/tutorials/modules/beginner/scripting/linear-interpolation – JinJi
另外,请考虑添加语言你的代码在标签中(如C#或Javascript),它会为你的代码添加着色它更具可读性。 –