Profile image

Taking Control of Game Cameras - Explained

18.4k CarnationRED  5.3 years ago

Here's how to control cameras when playing(not in designer):


What:

This Transform represents current camera's position and rotation

CameraManagerScript._currentCameraController.CameraTransform

And this is the camera's focus, modify it as well if needed.

CameraManagerScript.CameraFocalPosition


When:

It's very important to ONLY modify the Transform in the OnRenderObject method, AND restore it's original value in the OnRenderImage method. You must restore the camera data in "OnRenderImage" in your custom scripts, as it's not been modified by mod. Or the pilot may die: )

Why

It seems ServiceProvider.Instance.GameCamera.CameraPosition is not completely related to game's cameras. Camera's position can't be modified using it.
I tried adding custom cameras to the game, but I had not been able to solve some problems related to skybox.
So I came back for another way to modify game cameras: Reflection in C#. However, in using Reflection I found that, the camera position is calculated after LateUpdate is called. I still can't really control it.
I tested and figured out OnRenderObject is the right one in which we can modify the camera without being "fixed" be the game.
As for restoring the camera data in OnRenderImage, it's because the game simulation will be influenced in the next frame if we don't restore some imformations of the game (The airplane vibrates and blows up immediately when I turned the mod on). I haven't tested to find whether camera's position or CameraFocalPosition is the cause.


Note:

CameraManagerScript is from the game.
OnRenderImage and OnRenderObject are methods that you need to implement in a Monobehaviour of your mod.

  • Log in to leave a comment
  • Profile image
    2,507 OrderlyHippo

    So, could you actually have the camera focus on your target? Like 'fly by cam' but it focuses on the enemy while the camera itself remains with your plane? I'm never going to do this myself because I can't, but I want a mod that does it.

    2.5 years ago
  • Profile image
    18.4k CarnationRED

    I found a BUG: after switched weapon, the green target boxes are placed at wrong position on screen.
    I'm testing by modifying _camera field in TargetBoxScript

    5.3 years ago