How do you keep a crate bouncing?

2 replies [Last post]
Poonaka
User offline. Last seen 23 weeks 5 days ago. Offline
Joined: 24 Aug 2010

I've been playing around with the HelloPhysics sample code trying to get this to work. I want to make the crate bounce forever. Right now it loses height on every bounce and eventually comes to rest on the ground. I've tried adjusting the bounce properties and also added a collision event to apply a vertical force to the crate. I couldn't get the crate to stay on screen using applyForce. The crate would go barely off screen with applyLinearImpulse but would only bounce once.

How would I go about making an object bounce off the ground to the same height forever?

Replies

H4ch1
User offline. Last seen 1 hour 27 min ago. Offline
Joined: 27 Aug 2010

I did it with setting the bounce to 0, and on collision, char:setLinearVelocity ( x, y), with y as a negative value, and it works.
But I'd like to know if there's a way to access the x and y linear velocity value not without a getLinearVelocity, but like it works for the x and y coordinates, with name.x or name.y .

evank
User offline. Last seen 1 year 4 weeks ago. Offline
Joined: 16 Sep 2009

If you literally want to bounce to the same height, set bounce=1.0.

The "bounce" attribute (aka "restitution" in Box2D language) is literally the ratio between the height something falls from and the height it bounces back to. You can also set it higher than 1.0, but then things generally fly off the screen.

However, note that all the rapid math approximations in the Box2D engine can produce unstable "runaway" behavior in simulations where the bounce values are 1.0. For example, when the bounce value of the balloons in the "CollisionFilter" example were set to 1.0, the balloons would bounce faster and faster forever. As a result, they currently have bounce set to 0.95, which seemed more stable in a closed space.

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.