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$
3
  • $\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$
    – ruckus
    May 6, 2015 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$ May 8, 2015 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$
    – ruckus
    May 28, 2015 at 23:22

1 Answer 1

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$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .