My head is already ready to burst so please help. I made my camera move with W, S, A and D keys for up, down, left and right and also zoom with the mouse wheel. Everything works except for one bug: I cannot move the camera immediately after zooming, it just moves a little and drags the camera back. It only allows me to move the camera after waiting about one second or so… wtf:rage: processing speed or what?
This is the code I used:
private void Update ()
{
ZoomCamera();
MoveCamera();
}
private void MoveCamera()
{
float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
float y = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Translate(x, y, 0);
}
private void ZoomCamera()
{
float moveY = Input.GetAxis("Mouse ScrollWheel");
if (moveY != 0)
zoomDestination = transform.position + (transform.forward * moveY) * zoomSpeed;
if(zoomDestination != Vector3.zero zoomDestination.y < zoomMaxY zoomDestination.y > zoomMinY)
{
transform.position = Vector3.Lerp(transform.position, zoomDestination, zoomTime);
if (transform.position == zoomDestination)
zoomDestination = Vector3.zero;
}
if (transform.position.y > zoomMaxY)
transform.position = new Vector3(transform.position.x, zoomMaxY, transform.position.z);
if (transform.position.y < zoomMinY)
transform.position = new Vector3(transform.position.x, zoomMinY, transform.position.z);
}
Please, please help
EDIT: Sorry, here are the variables:
public float zoomMaxY = 1;
public float zoomMinY = 1;
public float zoomSpeed = 0.05f;
public float zoomTime = 0.25f;
public Vector3 zoomDestination = Vector3.zero;