I am creating a game which will have physics similar to those found in... Pong, or Breakout; that is: no gravity, no friction, full restitution.
this is working fine, until I introduce a twist: I actually want the player's ball pick up speed with every bounce, making it increasingly difficult for the player to keep up with. to do this, I have given the ball restitution of 1.1, however once this change is put in place, the ball seems to lose its y velocity after a little while!
to test the physics, I have set up a ball surrounded by four static rectangle walls. I then
to set the ball moving at a 45 degree angle; when the ball's restitution = 1, it continues to bounce at this angle for as long as I care to run the simulation. when, however, the ball's restitution is above 1 - say 1.1 - the ball speeds up as expected, but gradually loses y velocity until it is bouncing straight up and down.
I also tried setting the restitution of the walls > 1, and the restitution of the ball to 1, just to see if this would be any different, however it had the same effect (which is just as well: I only want the ball to speed up as it bounces; other objects should not increase in speed with every bounce).
I worry:
* there is some other variable I am not setting (I am currently setting friction, density and restitution for the objects; all objects have 0 friction, the walls have 0 density and 1 restitution, the ball has 1 density and 1.1 restitution)
* I misunderstand the effects of these variables
* there is a better solution (on writing this post, it occurs to me that restitution should go both ways, so objects the ball hit will also gain speed? this is not desired)
* Box2D does not expect/support restitution > 1 (I notice documentation says the value would "usually" lie between 0 and 1, though mathematically, I don't see why it shouldn't support restitution > 1)
* Box2D on some low level really expects a right-side up world with gravity and friction, and the world I want strays too much from that, such that unexpected behaviors crop up (this also doesn't seem likely to me, but... who knows - Box2D is new to me)
this is working fine, until I introduce a twist: I actually want the player's ball pick up speed with every bounce, making it increasingly difficult for the player to keep up with. to do this, I have given the ball restitution of 1.1, however once this change is put in place, the ball seems to lose its y velocity after a little while!
to test the physics, I have set up a ball surrounded by four static rectangle walls. I then
Code:
// Java
ball.applyImpulse(new Vec2(0.1f, -0.1f), ball.getWorldCenter());
ball.applyImpulse(new Vec2(0.1f, -0.1f), ball.getWorldCenter());
to set the ball moving at a 45 degree angle; when the ball's restitution = 1, it continues to bounce at this angle for as long as I care to run the simulation. when, however, the ball's restitution is above 1 - say 1.1 - the ball speeds up as expected, but gradually loses y velocity until it is bouncing straight up and down.
I also tried setting the restitution of the walls > 1, and the restitution of the ball to 1, just to see if this would be any different, however it had the same effect (which is just as well: I only want the ball to speed up as it bounces; other objects should not increase in speed with every bounce).
I worry:
* there is some other variable I am not setting (I am currently setting friction, density and restitution for the objects; all objects have 0 friction, the walls have 0 density and 1 restitution, the ball has 1 density and 1.1 restitution)
* I misunderstand the effects of these variables
* there is a better solution (on writing this post, it occurs to me that restitution should go both ways, so objects the ball hit will also gain speed? this is not desired)
* Box2D does not expect/support restitution > 1 (I notice documentation says the value would "usually" lie between 0 and 1, though mathematically, I don't see why it shouldn't support restitution > 1)
* Box2D on some low level really expects a right-side up world with gravity and friction, and the world I want strays too much from that, such that unexpected behaviors crop up (this also doesn't seem likely to me, but... who knows - Box2D is new to me)