simple in-game zooming

New to blender and even newer to 2.5. Was curious as to how one would go about zooming the camera in and out during a game using the middle mouse wheel.

Well, you could just move the camera on the local -Z axis (forwards or back) as you need it - a motion actuator set to local motion should be okay.

Camera objects have a ‘lens’ property you can adjust using python, like so:

    from bge import logic as g
    from bge import events

    c = g.getCurrentController()
    o = c.owner

    mRight = c.sensors['Right']

    if mRight.positive:

        o.lens = 50.0


        o.lens = 20.0

This zooms when the right mouse is pressed, but should be easy enough to modify for the mouse wheel.

I realize this is a bit off-topic, but why in your script do you do

from bge import logic as g
from bge import events

rather than

import bge

Is there a performance gain or something?

I would like to know this as well, its always puzzled me!

Naming the modules as you import them can simplify larger scripts, for example if you’re reading and writing lots of variables to and from GameLogic (or bge.logic as it’s now called).

It’s more coder preference than anything.

As python is dynamic binding (looks up variables/functions by name every time they used) it is actually a little bit faster to access (2 lookup) then (3 lookup). But most g is shorter to type then bge.logic even if g is possible overdoing it. If one skip the ‘as g’ part and use it is more readable and as fast as