Jump to content
  • Advertisement
Sign in to follow this  
dvdr

Avoid third person camera to go through walls

This topic is 3361 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

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
Advertisement
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
I hear the easiest way is to trace from the character out x units away; if the trace hits anything, the camera is placed at the intersection, if not, keep it x units away from the character.

EDIT:
Ninja'd.

Share this post


Link to post
Share on other sites
you usually want a volume for the trace (bounding sphere or box), with the size at least equal to the camera near plane distance.

Share this post


Link to post
Share on other sites
Thank you for the tips!
I've used Physx raycast and it's almost working. :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!