Animating orthographic camera size

Hey I am trying to change the orthographic size of the camera in-game, which cannot be done using the interface, as fov degrees and orthographic scale animation are not integrated to the game engine as far as I can tell. How do I animate this using python? I can only find the g.getCurrentScene().active_camera.lens value which is in mm (which is for perspective camera). Thanks :slight_smile:

you can use .ortho_scale example:

from bge import logic
cam = logic.getCurrentScene().objects['Camera']

cam.ortho_scale = 7

Assuming that the camera is named “Camera”.
You can usually find the python control for a particular attribute by hovering the mouse over it.
In this instance, by hovering over “Orthograpic Scale” it read the python control as well as a short description of what it does.

Be aware - this is valid for the Blender API only.

In this particular case the developers have chosen the same attribute name for the BGE API.
bpy.types.Camera.ortho_scale vs bge.types.KX_Camera.ortho_scale

It makes a lot of sense to do that. But better do not rely on it as it will not match most of the time.
bpy.types.Object.location vs. bge.types.KX_GameObject.localPosition

Beside of that the answer is perfectly fine

Thanks :slight_smile:

I just need to make this transition now… I think that the way to do this is something like the following (which I don’t know how to do in python yet):
Take property “fov” and set it to default value (20).
If "fov: > 10 (zoom value) and property “fov” not < 20
then add 1 when zooming in
subtract 1 when zooming out

this would run every tick so it would/should do a transition because it is never equal to 20.

Am I on the right track? Can you help me out, please? :stuck_out_tongue:

What do you want to make? FOV moving between 10 and 20?

#you need sensors with below names for mouse wheel up and down 
#connected to this script
import bge

cont = bge.logic.getCurrentController()
cam = bge.logic.getCurrentScene().objects['Camera']

if not "DefaultFOVset" in cont.owner:
    cam.ortho_scale = 20
    cont.owner["DefaultFOVset"] = True

FOV = cam.ortho_scale

if cont.sensors["MWHEELUP"].positive:
    if FOV &lt; 20:
        FOV += 1      # linear increase
        FOV /= 0.9    # exponential increase
        if FOV &gt; 20:
            FOV = 20
elif cont.sensors["MWHEELDOWN"].positive::
    if FOV &gt; 10:
        FOV -= 1
        FOV *= 0.9
        if FOV &lt; 10:
            FOV = 10

cam.ortho_scale = FOV

Pick one method of linear and exponential increases. You should then assign sensitivity values to it so the player can adjust how fast it scales up and down.

Thanks :). Here is the script I ended up with:

import bge

cont = bge.logic.getCurrentController()
cam = bge.logic.getCurrentScene().objects[‘Camera’]

if not “fov” in cont.owner:
cam.ortho_scale = 20
cont.owner[“fov”] = True

FOV = cam.ortho_scale

if cont.owner[“zoomed”] == False:
if FOV < 20:
FOV /= 0.95
if FOV > 20:
FOV = 20
elif cont.owner[“zoomed”] == True:
if FOV > 12:
FOV -= 0.25
FOV *= 0.99
if FOV < 12:
FOV = 12

cam.ortho_scale = FOV