camera blocking view

First of all: I know there are other threats regarding this subject, but hear me out:

I’m making a third person game and already have a camera that works the way I want. The only thing it’s missing
is that it places itself in front of an object that bloks the view.

since i’m very hapy with my camera now, i’m not looking for a complete code for a third person camera, just the
code for the blocking issue.

other solutions, like making the objects transparent are welcome as well!

THANKS IN ADVANCE!!

The easyest way wold be to cast a ray from the camera to the player and check if something is in the way. If so move the camera nearer towards the player until the obstacle is gone. Also check if there is still an obstacle behind the camera and move it back to its original distance by the time the way is free again.

Okay, I get what you are saying, just don’t know if I’m gonna do it the right way, cause I’m new and do most of the actions trough the game logic editor :stuck_out_tongue:

Hi! http://www.pasteall.org/blend/36635 (works only if only one object masks the player (if more objects masks the player, tell me it and I’ll change the code). You have to check object color and transparency in the material tab. All the obstacles must have an “obstacle” property)

http://www.mediafire.com/download/4t5qy68w94rqdtg/obstacleTransparency.blend (works with multiple objects)

Hi,

Thanks, I’ll try to work with your code, it does exactly what I was looking for! I hope I’m able to make it work :smiley:

when i do this, all my obstacles start behaving very weird!

the transparancy problem is fixed… evry obstacle has a property ‘obstacle’ the object color and transparancy problem is fixed, but it doesnt work.

I renamed the name ‘player’ to the name of my mesh, but still nothing.

hi, i did everything you siad, but couldn’t get it to work on my game… I also tried changing the name ‘player’ to the name of my character, but that didnt work either

hi, here’s the blend file like you asked…
I did conect the camera to the scriped, but still nothing… if you can make it work, please tell me how, so i can learn from it! :smiley:

i placed a random object in front of the camera to test is quickly :slight_smile:

game15_camera.blend (1.98 MB)

Hey! You just forgot to add an empty named “raySpawner” in an inactive layer. http://www.pasteall.org/blend/36647
And I realized that my script could crash blender (infinite while loop) so I corrected it.

Tell me if that works and if there are no crashes anymore. :slight_smile:

hi there, fist of all: sorry, I’ve been away for a few days.
The function works, but the game does crash after a few seconds…