Ball Bouncing problem

Post your tutorials and samples here.
Posts: 2
Joined: Fri Aug 24, 2012 5:13 am

Ball Bouncing problem

Postby oceaneast » Tue Sep 04, 2012 8:20 pm

In our game, we shoot a ball to hit other balls (The balls are connected to the ground with a mouse joint).

In most cases, we want the shooting ball keep bouncing if it hit other balls.

First we tried to set all the bubble's restitution to 1.0, but this will cause all the hanging balls keep bouncing which is not desired.

Then we set the restitution to 0.6, this is ok for the jointed balls since it will stopped bouncing after a while (it is jointed).
But the shooting ball will also be slowed down and even stopped after a while.

We want the shooting ball keep bouncing, so we tried to apply a extra force to the shooting ball after it hit other balls but cannot get satisfied result, the shooting ball's movement seems to be unnatural.

Any suggestions? thanks.

Posts: 34
Joined: Sat Mar 01, 2014 7:39 am

Re: Ball Bouncing problem

Postby S986S » Sat Mar 01, 2014 2:46 pm

off the top of my head

In the beginContact of your collision Listener

if(!contact.isEnabled()) return;
if(contact.getFixtureA.userData == "Ball" && contact.getFixtureB.userData == null)
contact.getFixtureA.restitution = 0;
else if(contact.getFixtureA.userData == null && contact.getFixtureB.userData == "Ball")
contact.getFixtureB.restitution = 0;
else return;

If that doesn't work, you'll want to peg it into an array and then edit the restitution in the timestep

Return to “Tutorials and Samples”

Who is online

Users browsing this forum: No registered users and 1 guest