camera that wont go through wall, help?

i am trying to make a camera that wont go through walls, this is what i have so far, but it doesn’t work and the console doesn’t return any errors. im using 2.49, i was wondering if someone know how to do this?

cont = GameLogic.getCurrentController()

cam = cont.owner

ray = cont.sensors[“ray”]

if ray.positive:
cam.position = ray.hitPosition

Make sure the ray points along the right axis. Enable True Pulse at the ray sensor.

By the way:
If the ray points from the camera to the target object, you might still have something between the camera and the target (e.g. if there are two objects blocking the sight).

It might be better to send a ray from the target object to the camera. That means the hitPosition is the nearest to the target.

I hope I do not confuse you

third-person camera.blend (210 KB) This should help.

i saw a tut on this…http://www.blending-online.co.uk/8501/49279.html
has a demo file