如何讓閉路電視控制這裏的攝像頭 - Camera 。也就是說,它是在天花板上,它是在旋轉的X限制和Y是喜歡這裏 -閉路電視控制(unity3D)
public float Smoothness = 0.3F;
public Vector2 Sensitivity = new Vector2(4, 4);
public Vector2 LimitX = new Vector2(-70, 80);
public Vector2 LimitY = new Vector2(-60, 20);
private Vector2 NewCoord;
public Vector2 CurrentCoord;
private Vector2 vel;
void Update()
{
NewCoord.x = Mathf.Clamp(NewCoord.x, LimitX.x, LimitX.y);
NewCoord.y = Mathf.Clamp(NewCoord.y, LimitY.x, LimitY.y);
NewCoord.x -= Input.GetAxis("Mouse Y") * Sensitivity.x;
NewCoord.y += Input.GetAxis("Mouse X") * Sensitivity.y;
CurrentCoord.x = Mathf.SmoothDamp(CurrentCoord.x, NewCoord.x, ref vel.x, Smoothness/2);
CurrentCoord.y = Mathf.SmoothDamp(CurrentCoord.y, NewCoord.y, ref vel.y, Smoothness/2);
transform.rotation = Quaternion.Euler(CurrentCoord.x, CurrentCoord.y, 0);
}
但我的版本的作品不正確。 謝謝!
對於連續使用Quaternion.euler(歐拉角)輪換是一種不好的做法:https://www.sjbaker.org/steve/omniv/eulers_are_evil.html。您應該使用transform.Rotate()或transform.RotateAround(),因爲它們不會使用EulerAngles執行旋轉。另一方面,如果你需要存儲一個給定的位置,eulerAngles很好,因爲它們的可讀性! – Greg
我發現這個腳本 'public float speedH = 2.0f; public float speedV = 2.0f; 私人浮動偏航= 0.0f; 私人浮動間距= 0.0f; void Update(){ yaw + = speedH * Input.GetAxis(「Mouse X」); pitch - = speedV * Input.GetAxis(「Mouse Y」); transform.eulerAngles = new Vector3(pitch,yaw,0.0f); ',但我無法弄清楚這個限制。如果我把 'if(gameObject.transform.rotation.x <116F) {pitch} - = speedV * Input.GetAxis(「Mouse Y」); }' 然後就不會有反應 – 50VAJJ
不好意思。我無法正確格式化 – 50VAJJ