enter image description here

How would I incorporate the ortho zoom to my mouse wheel?

This seems close to what I need, but I don't know why it's not working.

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

Here's another one, I can only get it to zoom out. https://blender.stackexchange.com/a/58556/37524


1 Answer 1

  • Typo on the line 18 positive:: to positive:

  • You need 2 sensors for each of detect wheel up and down. And the sensors have to be connected to the python controller. This is why you got only one of zoom out or in.

  • You have to make the names in blender to be consistent with the names in the script, also the script file name.screen shot

Advice: You can open console from menu Window > Toggle System Console. The console shows error messages from BGE when BGE is running. Be carful, closing the console window closes whole blender.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .