Camera questions...

Well… The thing is, now I have to find a way to make this camera thing work well…

The main problem I’m having is that my camera (attached to my character) keeps going through the walls, so my view is usually blocked, since there are quite a lot of walls in my game…

So my current plan is to attach a collision sphere to the camera, and make it such that it will slide against the walls, and to attach another collision segment in front, which will make anything blocking the view to the player transparent (alpha 50)

However… The issue that I have at the moment is making it such that the camera will move back to the original position when there is space, as now it will just stay where it is pushed to, causing the camera angle to really screw up… And my idea of making whatever i hit transparent has a weird bug of sorts where at certain points, my characters’ image will suddenly disappear…

So I want to ask, has anyone ever done this before? Cameras with collisions. And if so, can you share your experience with it? Is this the only way I have, or is there a better way? And if so, how do I make it actually work good?

Thanks, sorry for the trouble…

I have not done it this way, but what you are doing should be possible. I think it would look better if you do sliding or hiding but not both - that is how I seen most games do it.

Maybe add a python tasks that moves the camera slowly to its original possession, but keep the collision fx stronger?

Sorry, but what do you mean by keeping the collision fx stronger? It sounds real interesting, and might help witht the crappy collision of the camera at ht emoment, after i implemented everything…

I wouldn’t actually give the camera a physical body. It will get stuck on things.

Here’s some psuedocode that comes to mind:

At initialization:

  1. reparent the camera to the player
  2. store coordinates of desired camera position relative to player and set the camera to this position now
  3. calculate and store the distance of the desired camera position from the player
    Each frame:
  4. perform a ray trace from the player to the desired camera position
  5. if there is no collision there is nothing obstructing the cameras view of the player, place the camera at the desired offset you stored earlier otherwise continue with the following
  6. retrieve the distance of the first collision in the ray trace
  7. place the camera at desired camera position * (distance to desired camera position / distance to collision)

This seems to be the way most commercial games with an over the shoulder style third person camera do things.