Page 1 of 1
Chase Camera
Posted: Mon Sep 24, 2012 9:27 pm
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?
Re: Chase Camera
Posted: Mon Sep 24, 2012 10:01 pm
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.
Re: Chase Camera
Posted: Mon Sep 24, 2012 10:22 pm
by Stevemata
Yeah, I got it working, something weird I don't know. That's exactly the solution I was doing.