# Resetting camera after camera collision (BGE)

When my camera collides with my wall, after I move the camera back to where it isn't colliding with anything, the camera stays fixed very closely to the player. What can I add to the code below to fix that(or fix it with the blender logic bricks)?

from bge import logic

def collision(cont):

own = cont.owner
scene = logic.getCurrentScene()
target = scene.objects['playerOne']
ray = cont.sensors['Ray']

if ray.positive:
own.worldPosition = ray.hitPosition

• could you [else: play animation that takes it back to original position]? don't know how to python that, but i'm sure you could figure it out. – Scalia May 6 '15 at 23:31
• Yeah that sounds like a good idea. I'm pretty new to python, but i'll try to look around and see what I can find online. – Michael Akers May 8 '15 at 0:41
• what about getting rid of the If statement? that way, even if it's false it the end of the line for ol' mr. camera – Scalia May 28 '15 at 23:22

Add an empty, slightly behind the player, and put the ray on that, set the ray distance to however long you wan it to be, and turn on true level triggering.

you will need to change the code a very small amount:

from bge import logic

def collision(cont):

own = cont.owner
scene = logic.getCurrentScene()
target = scene.objects['Camera.001']
ray = cont.sensors['Ray']

if ray.positive:
target.worldPosition = ray.hitPosition


and viola! mow the camera is added to a position based on the empties ray! if the ray is obstructed, the camera moves to the closest position!