# When a ball hits a plane

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

## 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 on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634088
• Total Posts
3015447
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!