How can I change the focal lenght of a camera with python?

I’m trying to change the focal length of a camera in-game.
I have tried this:

cameraFL =["Camera"]
cameraFL.lens = 11.0

This doesn’t do anything in-game but changes the focal length of the camera in Blender when I stop the game.
Maybe it doesn’t work when I’m combining it with Class KX.
Also when I try to change the camera in-game, it doesn’t work. =["CameraLIFT"]

This changes the camera after I stop the game in Blender.

I think the BPY module is not for working in the game engine, but the editor.

I can’t test this right now, but I think this would work - run it from a camera:

from bge import logic
cont = logic.getCurrentController()
cam = cont.owner
cam.lens = 11.0

Edit: Replaced “fov” with “lens”.

1 Like

Thank you, this works.

One is glad to have been of service Ø__^ If I may ask, what are you trying to create?

I wanted to create a zoom in and zoom out for specific locations in-game.
In this case, looking at what kind of items are on a shelf.

Ooooh! Interesting! Using the camera effectively is a very good way to distinguish your game : D Best of luck!

1 Like