Hello there,
I’ve been working on this for a while as Starfox was my favourite game growing up, and I’m very excited to flesh it out.
I’ve been looking for a better way to control the camera, as i want it zoomed in but able to move sideways/up and down.
The issue is, i can only get about 22 units left or right, and 12 units up or down moving the camera.
I’ve got the x and y range to be 2000
not sure why it won’t keep moving the camera.
void ClampPosition()
{
//stores the objects transform = camera space rather then world space
Vector3 pos = mainCamera.WorldToViewportPoint(transform.position);
pos.x = Mathf.Clamp01(pos.x);
pos.y = Mathf.Clamp01(pos.y);
if (xThrow != 0 || yThrow != 0 )
{
MoveCamera(pos);
transform.position = mainCamera.ViewportToWorldPoint(pos);
}
}
private void MoveCamera(Vector3 pos)
{
Vector3 mainCameraUpdated = mainCamera.transform.localPosition;
mainCameraUpdated.z = zCameraPosition;
Debug.Log("pos " + pos);
if (pos.x > .85f && xThrow > 0 || pos.x < .15f && xThrow < 0 )
{
mainCameraUpdated.x += xThrow ;
mainCameraUpdated.x = Mathf.Clamp(mainCameraUpdated.x, -xRange, xRange);
}
if (pos.y > .85f && yThrow > 0 || pos.y < .15f && yThrow < 0)
{
mainCameraUpdated.y += yThrow ;
mainCameraUpdated.y = Mathf.Clamp(mainCameraUpdated.y, -yRange, yRange);
}
mainCamera.transform.localPosition = Vector3.SmoothDamp(transform.localPosition, mainCameraUpdated, ref velocity, smoothTime);
Mathf.Clamp(mainCamera.transform.localPosition.x, -xRange, xRange);
Mathf.Clamp(mainCamera.transform.localPosition.y, -yRange, yRange);
}