2
$\begingroup$

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
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Scalia May 6 '15 at 23:31
  • $\begingroup$ 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. $\endgroup$ – Michael Akers May 8 '15 at 0:41
  • $\begingroup$ 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 $\endgroup$ – Scalia May 28 '15 at 23:22
1
$\begingroup$

Here's the answer;

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!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.