1
\$\begingroup\$

I am developing a simple side scrolling game. I want to target and zoom camera on player when he dies. But it rotates the screen, and I want to prevent it. I'm copying the snippet of code here :

IEnumerator ZoomIn()
{
    while (GameCamera.orthographicSize > 2) {
        yield return new WaitForSeconds (0.01f);
        GameCamera.orthographicSize -= 0.2f;
    }
}

public void ZoomCamera()
{
    CameraZoomSource.Play ();
    StartCoroutine (ZoomIn ());
}

public void TargetPlayer()
{
    transform.LookAt (PlayerTransform); 
    GameCamera.orthographicSize = 3;
    GameCamera.transform.Rotate (0, 0, -2);
}

Should I change anything in this?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You are rotating the Camera, why would you not expect it to rotate? \$\endgroup\$
    – jgallant
    Commented Jun 24, 2016 at 11:25
  • \$\begingroup\$ still it rotates the screen. \$\endgroup\$ Commented Jun 24, 2016 at 11:54
  • \$\begingroup\$ Are you using a script for camera to follow the player? What does CameraZoomSource.Play (); do? What's the position of the camera when the player dies? \$\endgroup\$ Commented Jun 24, 2016 at 14:20

1 Answer 1

1
\$\begingroup\$

I've solved a problem with a simple logic. Now, When player dies, camera position will be set exact to the player position, thus focusing the camera on player. And after that the orthographic size of the camera will reduced to give it zooming effect. Here is code snippet :

IEnumerator ZoomIn()
{
    while (GameCamera.orthographicSize > 2) {
        yield return new WaitForSeconds (0.01f);
        GameCamera.orthographicSize -= 0.2f;
    }
}

public void ZoomCamera()
{
    StartCoroutine (ZoomIn ());
}

public void TargetPlayer()
{
    Vector3 TempCameraPos = transform.position;
    TempCameraPos.x = PlayerTransform.position.x;
    TempCameraPos.y = PlayerTransform.position.y;
    transform.position = TempCameraPos;
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .