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
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
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
āfovā=āfovā*0.9
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?
What do you want to make? FOV moving between 10 and 20?
#untested
#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 < 20:
FOV += 1 # linear increase
FOV /= 0.9 # exponential increase
if FOV > 20:
FOV = 20
elif cont.sensors["MWHEELDOWN"].positive::
if FOV > 10:
FOV -= 1
FOV *= 0.9
if FOV < 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