Chase Camera

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Stevemata
Posts: 33
Joined: Sat Mar 17, 2012 11:11 pm

Chase Camera

Post by Stevemata »

Hi Norbo, I'm having trouble with the chase camera, in some situations in my level the camera can see out of the level. For example, on faces that slope over the player, the camera can see through the level. I checked out the chase camera positioning, for some reason I can't get it move the camera closer to the player to avoid seeing through the wall.

Code: Select all

               
if (entityToChase.Space.RayCast(new Ray(lookAt, backwards), distanceToTarget, rayCastFilter, out result))
{
     Position = lookAt + (result.HitData.T) * backwards; //Put the camera just before any hit spot.
}
Added or subtracting some value from the result.HitData.T seems to have no effect, am I doing it wrong?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Chase Camera

Post by Norbo »

Changing:

Code: Select all

Position = lookAt + (result.HitData.T) * backwards;
to

Code: Select all

Position = lookAt + (result.HitData.T - x) * backwards;
for some nonzero x will have an effect so long as the backwards vector is not the zero vector and the Position is not arbitrarily overwritten later. If it has absolutely no effect, there are some shenanigans going on.

Here's a modified version of the chase camera code that introduces such a margin.

Code: Select all

                if (entityToChase.Space.RayCast(new Ray(lookAt, backwards), distanceToTarget, rayCastFilter, out result))
                {
                    Position = lookAt + (Math.Max(result.HitData.T - chaseCameraMargin, 0)) * backwards; //Put the camera just before any hit spot.
                }
                else
                    Position = lookAt + (Math.Max(distanceToTarget - chaseCameraMargin, 0)) * backwards;
It is still possible to see through the level if the backwards ray is very nearly parallel to a surface such that the screen is positioned with a near plane intersecting scene geometry. To avoid this problem entirely, a sphere-based convex cast could be used instead of a ray cast. A sufficient ray margin gets rid of most issues, though.
Stevemata
Posts: 33
Joined: Sat Mar 17, 2012 11:11 pm

Re: Chase Camera

Post by Stevemata »

Yeah, I got it working, something weird I don't know. That's exactly the solution I was doing.
Post Reply