Jump to content
  • Advertisement


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


Why wont this collision code run?

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

Below is code to decide if a particle has hit the "floor" ( a plane that is parallel to xz at the origin): static CVector normal (0, 1, 0); static CPlane floor(normal, 0); static float bouncePercent = 0.5f; static float distPlane = 0.0f; static float distPlanePost = 0.0f; //MessageBox(NULL, "We're Updating Particles", "Bubbles",MB_OK | MB_ICONEXCLAMATION); for (int i = 0; i < m_numParticles; ++i) { CVector DestinationPos = m_particleList.m_pos + m_particleList[i].m_velocity * elapsedTime; distPlane = floor.DistanceToPlane(DestinationPos); distPlanePost = floor.DistanceToPlane(m_particleList[i].m_pos); if((distPlane < 0 && distPlanePost >= 0) || (distPlane >= 0 && distPlanePost < 0)) { MessageBox(NULL, "We're Updating Particles", "Bubbles",MB_OK | MB_ICONEXCLAMATION); m_particleList[i].m_velocity.y = -m_particleList[i].m_velocity.y; } m_particleList[i].m_pos = m_particleList[i].m_pos + m_particleList[i].m_velocity * elapsedTime; When this code is run, the if statement with the MessageBox command never evaluates to true. Ne1 know why not? Thx Edited by - executor_2k2 on February 5, 2002 1:02:47 AM

Share this post

Link to post
Share on other sites
I see only one reason why this code might prevent the if condition from evaluating true at some point. Does your DistanceToPlane() method return the magnitude of the distance (which would only ever be >= 0 and never < 0)?

It that''s not it, then I believe the problem must be outside this block of code. Perhaps your velocity is always moving the particles away from the plane? How do you set your velocity initially? And how do you use acceleration to update your velocity? Are you just using gravity? I see your particle system is called "Bubbles." Are you wanting your particles to float? In which case why should they ever go through the floor....

If DistanceToPlane() really just returns height above the plane (which can be negative when an object is below the plane), then perhaps you might change the function name just to avoid confusion---maybe call it HeightAbovePlane()?

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post

Link to post
Share on other sites

  • 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!