Sign in to follow this  
dvdr

Avoid third person camera to go through walls

Recommended Posts

Hello, I'm developing a video game using C++ and OPENGL. I use a third person camera to follow the main character which works properly. The camera is always behind the character but when the character has a wall behind him, the camera goes through it. That means that sometimes I can't see the character because the walls are in the middle. I've implemented collision detection (with Physx) so the character is not able to go through the objects and the walls. My idea is to zoom the camera in the character's direction in these situations. The problem is how to detect the walls or any object that is in between. Is there any easy (or not so easy) way to solve that problem? Thank you in advance!

Share this post


Link to post
Share on other sites
You could do a raycast from the character's position to the desired camera position. If the raycast returns a position closer than the goal camera position, then use that value with a small buffer so the camera near plane doesn't intersect the geometry. PhysX has built in raycast support so that should be pretty easy if you use their functions against your collision world.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this