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?
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.
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 .