# FPS Wall Collision

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

## Recommended Posts

Hi all, I have a question about FPS wall collision, currently, I have a wall defined as two triangles as you would expect and this method shows if the camera and the wall are colliding. void PhysicsEng::PlayerEnvCollision(ParticleProperties* playerData, Rect3D* Env) { float angletotal = 0.0f; float mag1, mag2; D3DXVECTOR3 v1, v2; vector<D3DXVECTOR3> corners = Env->getCorners(); for (int i = 0; i < corners.size(); i++) { if (i < (corners.size() - 1)) { v1 = corners - (*playerData).Position; v2 = corners[i+1] - (*playerData).Position; mag1 = sqrt((pow(v1.x, 2)) + (pow(v1.y, 2)) + (pow(v1.z, 2))); mag2 = sqrt((pow(v2.x, 2)) + (pow(v2.y, 2)) + (pow(v2.z, 2))); angletotal += acos((D3DXVec3Dot(&v1, &v2)) / (mag1 * mag2)); } else { v1 = corners - (*playerData).Position; v2 = corners[0] - (*playerData).Position; mag1 = sqrt((pow(v1.x, 2)) + (pow(v1.y, 2)) + (pow(v1.z, 2))); mag2 = sqrt((pow(v2.x, 2)) + (pow(v2.y, 2)) + (pow(v2.z, 2))); angletotal += acos((D3DXVec3Dot(&v1, &v2)) / (mag1 * mag2)); } } if (angletotal >= 6.27) { } } Sorry for the bad formatting there, but basically, if the total angle is around 2PI then there is a collision. Now i cant seem to find a good way of getting the player to stop at the wall. It seems as the X value of the camera changes from dead center of the plane the distance at which a collision is detected changes in the z-axis if you get what I mean. So basically I want a fool proof way of stopping the player at the wall, so that even if the wall is at an angle the player will rebound correctly, hopefully it wont be too much work from this but I just cant seem to get anything down. Any help is appriciated.

##### Share on other sites
Never mind, got this solved, just needed to combine this with a plane - point distance method and its all gravy. If anybody else comes here, feel free to message me for help.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633759
• Total Posts
3013719
×