0
我正在嘗試爲我的遊戲創建一個RTS-esque攝像機控制系統,並且我碰到了牆壁,我不確定如何操作。Unity 5.4 - 沒有FoV操縱的變焦RTS攝像機
我希望發生的是:
- +鼠標拖動=移動相機,在世界各地(作品)
- 鼠標滾輪點擊+拖動=旋轉相機在世界各地(作品)
- 鼠標滾輪=放大/縮小使用MoveToward/Transform.Forward..etc(八九不離十作品)
在另一個腳本我的FoV變焦的工作,但它不是理想的工作經驗的類型我想創建。相反,我正試圖以指向它的方向物理移動相機。
這當前的腳本是90%的功能,因爲它可以做上面列出的所有的事情,但是當我點擊並拖動到滾動縮放,相機復位到原來的位置後移至新位置。
這裏是更新()會發生什麼:
void Update()
{
currentPosition = transform.position;
scrollAxis = Input.GetAxis ("Mouse ScrollWheel");
if (Input.GetMouseButtonDown (0))
{
mouseOrigin = Input.mousePosition;
isPanning = true;
}
// cancel on button release
if (!Input.GetMouseButton (0))
{
isPanning = false;
}
//move camera on X & Y
else if (isPanning)
{
Vector3 pos = Camera.main.ScreenToViewportPoint (Input.mousePosition - mouseOrigin);
Vector3 move = new Vector3 (pos.x * -panSpeed, pos.y * -panSpeed, 0);
Camera.main.transform.Translate (move, Space.Self);
transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, 0);
transform.localPosition = new Vector3(transform.position.x, transform.position.y - (transform.position.y - (initialPosition.y)), transform.position.z);
}
//rotate camera with mousewheel click
if (Input.GetMouseButton(2)) {
yRotation -= Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
yRotation = Mathf.Clamp(yRotation, -80, 80);
xRotation += Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
xRotation = xRotation % 360;
transform.localEulerAngles = new Vector3(yRotation + initialRotation.x, xRotation + initialRotation.y, 0);
}
//zoom with scroll
if (Input.GetAxis("Mouse ScrollWheel") > 0 && !isPanning) {
transform.Translate(Vector3.forward * Time.deltaTime * 10000f * scrollAxis, Space.Self);
transform.localPosition = new Vector3(transform.position.x, transform.position.y, transform.position.z);
}
}
任何幫助非常感謝,謝謝!