Jump to content
  • Advertisement
Sign in to follow this  
Winegums

When a ball hits a plane

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

This is perhaps an obvious question, but it's really stumping me. i'm trying to simulate a simple sphere->plane collision. The collision checking is going fine, but the resolution of the check is confusing me. The sphere is dropped onto the plane (ie gravity is the only force acting on it). The sphere then hits the plane, but I don't know how this is meant to resolve. I've kept it simple initially and just inverted forces (which I think is all that'd happen anyway if the sphere was dropped along (0,1,0), which is also the plane normal). If I simply invert velocity, the sphere behaves almost as expected, except the downwards acceleration grows and grows and eventually the sphere's maximum height starts to drop (I wasn't sure if this was a rounding problem or a physics problem...certainly from what I can see the ball should bounce indefinitely if we're not considering any other forces). The fact that acceleration in the y-axis grows and grows doesn't seem right. However, setting acceleration to zero after the collision makes the sphere gain height. Have I ignored some important rule of physics?

void SpherePhysicsClass::Update(float timeDelta)
{
	//Store our last data
	this->mAccelPrev = this->mAccel;
	this->mVelPrev = this->mVel;
	this->mPosPrev = this->mPos;

	//Update positions
	this->mAccel += timeDelta * Vector3(0.0f,GRAVITY_ACCELERATION ,0.0f);
	this->mVel += this->mAccel * timeDelta;
	this->mPos += this->mVel * timeDelta;
}

int main()
{
 ....
  if(collision)
{
	sphere->mVel *= -1.0f;
}
      }
}

Share this post


Link to post
Share on other sites
Advertisement
The acceleration on your ball should just be a constant, don't increase it every update and don't multiply by timeDelta there.

Like this:
this->mAccel = Vector3(0.0f,GRAVITY_ACCELERATION ,0.0f);


You may also want to be more careful about your time integration. If g is -10 m/s^2, for example, how far should the ball move in one second starting from rest? (A: 5m) How far does yours move? (A: 10m)

Once those things are fixed your answer will be better but to get it perfect you'll have to calculate the exact time of impact and split the time step during which the collision occurs.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!