Jump to content
  • Advertisement
Sign in to follow this  
roos

Camera clipping

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm making a game with a 3rd person perspective (if you've played Max Payne 2, it's somewhat like that). Of course with a third person camera, you have to be careful because, if you simply place the camera to be "X feet behind the main character", then the camera might end up behind a wall or something. The usual solution (I think) is to simply cast a ray from the lookat point to the camera position. If the ray collides with anything, and if the distance to the colliding object is less than the distance from the lookat point to the camera, then there's something blocking, so move the camera to the point of the ray intersection. Unfortunately, doing this causes the camera to "jolt" a lot as you move around. For example, say you're strafing with your back to a wall, and you pass by a doorway. When the wall is right behind your back, the camera will be clipped so that it's right behind you, but when you pass the doorway, suddenly it will be 20 feet away or whatever. There's no question about the fact that the camera has to be clipped in this case, but is there any way to smooth out the "jolt"? I guess one way to do it is, try to detect ahead of time if the camera needs to be moved closer to the lookat point. To do this, it'd probably require casting multiple rays on either side of the original ray, and then interpolating the results somehow... I think this would work, though it's kind of a brute force, inefficient way to do it :/ Thanks in advance, roos

Share this post


Link to post
Share on other sites
Advertisement
You should look at Jak & Daxter's camera. The problem you're talking about is extremely hard, and they seem to have a good solution. First they keep a bounding sphere around the camera, and if that penetrates anything, it starts to slow down or starts planning to avoid the geometry. If you go around a corner or something, I think it shoots multiple rays and possibly uses the NPC Nav-meshes to locate a position to reorient to. Also, I think they cast rays to multiple points on the character to test occlusion, so that if you walk in front of a pole or something, the camera doesn't thing its lost sight.

Other techniques are to get the bounding boxes of objects in the camera's frustum and test the distance of the corners (in screen-space) from the view axis, to "predict" when something might soon occlude the camera and start moving it forward. Smoothing motion and orientation is commonly done with critically damped springs (GPG4).

In the end, there's no "right" answer. All 3rd person camera systems are unwieldy at one point or another. Just play a bunch of games and see which ones you like and figure out what they do.

Share this post


Link to post
Share on other sites
Awesome, thanks so much for the info :) I think I'll split it into 2 parts then.. First, cast extra rays to make sure the camera doesn't go crazy when there's a pole in the way, and 2 is to predict when something's going to be in the way so a smooth transition can be made.

Share this post


Link to post
Share on other sites
I've just thought of a cool, but difficult to implement alternative. What if the scenery that is in the way fades to near transparent? With backface culling this might be very difficult (you probably wouldn't ever see a wall from behind normally) but I thought I'd mention it because it should look rather nice.

Mark
Sound Effects For Game Developers
http://www.indiesfx.co.uk

Share this post


Link to post
Share on other sites
Quote:
Original post by Mark Sheeky
I've just thought of a cool, but difficult to implement alternative. What if the scenery that is in the way fades to near transparent? With backface culling this might be very difficult


Yeah, a lot of games do that. It's actually easier to do with backface culling since you don't have to worry about seeing the inside-out part of the far face of the wall. Most PS2 games don't cull back-faces so you'll see objects inside out a lot of times when they start to go transparent (and then they do start culling at a certain level of transparency).

I don't particularly like the effect... Actually, one variation that I do like (I forget which game does this), is that they broke their models up into a 'top-half' and 'bottom-half', and just alpha out the top half. So you still get a good feeling of object solidness and depth without losing view.

The problem also really depends on whether you keep the camera locked behind the player or you let it free-look around. Mark of Kri for instance does both... Normally the camera is always behind the player until you go into battle, and then it chooses its own path around whatever geometry is around to keep the whole fight in view.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!