Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Change camera fov cause off center effect ?

Discussion in 'Editor & General Support' started by Go2ready, Jun 1, 2015.

  1. Go2ready

    Go2ready

    Joined:
    May 8, 2015
    Posts:
    29
    Hello there,

    I am trying to implement turret rotation/aiming with zoom in zoom out effect, so imaging your gun mounted on tank will turn to follow your camera. And I have some peculiar effect when I change my camera fov, here comes the screen shots:

    near_v.png (Fov = 60)
    So here you can see the red reticle(or whatever the aiming stuff is called) is in aligned on dead center before zoom in, you cant see my mouse in the screen shot, but my mouse is locked on the center of the viewport and it is pointing at the dead center of the reticle.

    far_v.png (Fov = 15)
    Here comes the zoomed effect, you can see that reticle is off center now, you cant see my mouse but my mouse which indicates the dead center on viewport is still locked inside the blue circle.

    Debug log is print two ray cast result, one from center of viewport(Camera Pointing) and another one from my gun(Barrel Pointing). Both of them does not change between the zooms, sorry for the +-0.1 shift is caused by me trying to capture screen shots.

    And when I fire the gun, to bullets goes to where the red reticle indicates, which is what I am expecting. Since I was aiming at the top bush before zooming and I have not touch the mouse.

    So I am wondering why changing fov on main camera causing this effect. Base on my understanding, the pivot point for changing fov should be on center.

    Here is the code for zooming camera(Simple zooming...):
    Code (CSharp):
    1. GetComponent<Camera>().projectionMatrix = Matrix4x4.Perspective(fov / CameraStateController.FieldOfViewDedector, aspect, near, far);
    And if that matters, I do used two camera, one main and one GUI for my game. In this case I am only changing the fov of the main camera, red reticle is implemented by converting Barrel Pointing Point onto the GUI camera viewport. Although I personally can't see this is the reason causing this...

    Thank you for your help! I can provide addtional info(code screen shot etc.) if needed! :)
     
  2. sys12

    sys12

    Joined:
    Apr 27, 2015
    Posts:
    9
    It seems that changing fov causing problem when you cast ray from screen point to world. Have you tried to use mouse point to ray as well?
     
  3. Go2ready

    Go2ready

    Joined:
    May 8, 2015
    Posts:
    29
    I tried, it does not work. I also did debug.draw on ray it case. They ray itself unsurprisingly does not change on change of fov, it must have something to do with the hud....
     
  4. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    You are casting a ray after changing the fov, right? I suppose it could also be a hud cam. Did you try with hudcam disabled?
     
  5. Go2ready

    Go2ready

    Joined:
    May 8, 2015
    Posts:
    29
    thank you all guys! The problem is solved, it is because the aiming was not in dead center at the first time, tiny offset will result in larger difference after changing fov, you are all amazing!