#### Archived

This topic is now archived and is closed to further replies.

# 3rd person camera collision

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

## Recommended Posts

Hi, im doing a game with a 3rd person camera, now i wonder whats the best way of handling the collision detection for the camera?I have some rough terrain and i have solved it so that if the camera hits the ground it simply stays a little above the ground. My ray is casted down from the camera but the problem comes when you move the camera fast sideways over the terrain because you get very jagged movements if you just put it to the new Collision y point and if you try to do a smooth elevating of the camera then it sometimes becomes too slow and the camera stays under the ground... any ideas?

##### Share on other sites
A solution to this problem can be found in refining the function you use to get the height at a particular position on the terrain. At the moment you seem to take the height of the nearest point - a bit of interpolation, and voilà: no rough steps anymore:

float p_fX, p_fZ; // x/z coordiantes of the camera floating above your terrainUINT iIndexX = (UINT)p_fX; if( p_fX < 0.0f ) iIndexX = 0;UINT iNextIndexX = iIndexX + 1; if( iNextIndexX >= m_iGridSize ) iIndexX = iNextIndexX = m_iGridSize - 1;UINT iIndexZ = (UINT)p_fZ; if( p_fZ < 0.0f ) iIndexZ = 0;UINT iNextIndexZ = iIndexZ + 1; if( iNextIndexZ >= m_iGridSize ) iIndexZ = iNextIndexZ = m_iGridSize - 1;float fDX = p_fX - (int)p_fX;float fDZ = p_fZ - (int)p_fZ;float fBaseHeight1 = m_pHeightValues[ iIndexZ * m_iGridSize + iIndexX ];float fBaseHeight2 = m_pHeightValues[ iIndexZ * m_iGridSize + iNextIndexX ];float fHeight1 = fBaseHeight1 + ( m_pHeightValues[ iNextIndexZ * m_iGridSize + iIndexX ] - fBaseHeight1 ) * fDZ;float fHeight2 = fBaseHeight2 + ( m_pHeightValues[ iNextIndexZ * m_iGridSize + iNextIndexX ] - fBaseHeight2 ) * fDZ;float fFinalHeight = fHeight1 + (fHeight2 - fHeight1) * fDX;

Hope this helps ...

[edited by - Reita on June 3, 2003 6:39:00 AM]

##### Share on other sites
Thanks for the reply, i do a Tri point interpolation os the slope should be fine, the i didn''t explain (wrote a little too fast before) is that i can''t seem to set the exact position of the camera using the point on the heightmap since my camera class uses a position and the an pitch angle to determine at which angle the camera is using the origo of the lookAt object.

So what i do is that i change the pitch angle when a collision occurs, i know this must be wrong but i can''t seem to change the cameras height position in any other way... anyways im trying a few solutions but please tell me if you have some more ideas

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 103
• 11
• ### Forum Statistics

• Total Topics
632977
• Total Posts
3009673
• ### Who's Online (See full list)

There are no registered users currently online

×