Jump to content
  • Advertisement
Sign in to follow this  
Maddius

FPS Wall Collision

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

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 this post


Link to post
Share on other sites
Advertisement
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.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!