Camera zoom and collision

Hello !

I’v some problems with a camera who rotate on a target.

I explain :

I have a camera who rotate around a target when I move the mouse.
I want zoom and zoom out with the mouse wheel and I want she was blocked by physical objects like floor, walls , etc.
Actually only the motion of rotation work.
Could someone help me? :frowning:

I use Blender 2.68 and here is my camera code :

from bge import logic as G
from bge import render as R
from bge import events

sensitivity = 2.0

cont = G.getCurrentController()
owner = cont.owner

if “oldX” not in owner:
G.mouse.position = (0.5,0.5)
owner[“oldX”] = 0.0
owner[“oldY”] = 0.0

x= 0.5 - G.mouse.position[0]
y = 0.5 - G.mouse.position[1]

x *= sensitivity
y *= sensitivity * 0.1

owner['oldX'] = (owner['oldX']*0.99 + x*0.01)
owner['oldY'] = (owner['oldY']*0.99 + y*0.01)
x = owner['oldX']
y = owner['oldY']

owner.applyRotation([0, 0, x], False)
owner.applyRotation([y, 0, 0], True)

G.mouse.position = (0.5,0.5)

zoom = owner["zoom"]

keyboard =
if keyboard[events.WHEELUPMOUSE]:
    zoom -+ 1.0
if keyboard[events.WHEELDOWNMOUSE]:

owner.scaling = [zoom, zoom, zoom]

owner["zoom"] = zoom

This depends what you mean with “blocked”.

What should happen on interactions with other objects?

You might want to have a look at the FreeViewControl. It tries to keep the target in view, while avoiding intersection with physics objects.

I know of another simpler avoidance strategy: move the camera to the nearest face to the target (the hitpoint of a ray from target towards the camera). This way the camera will avoid obstacles too.

By interactions with other objects, I mean that my camera dont pass through those objects.
I’v try to download your demo of the free view with the pokeball but this one dont work on my blender :confused:

What I mean is: “dont pass through those objects” is pretty vague. What should happen in this case?

I will look at my demo. I haven’t tried it recently.

Its ok. The Mobious solution work well. Its not exacly what I looking for but it’s still very effective !
I’ll change juste a little thing, when an object is not in “block_camera” but very close of the camera, it becomes slightly transparent.

Thank you for your help Mobious ! :wink: