Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Dynamic object never stops bouncing on static floor
Started by coronarocks Jul 28 2014 09:03 AM

- - - - -
8 replies to this topic
physics bouncing
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

coronarocks

[GLOBAL: userInfoPane.html]
coronarocks
  • Starter
  • PipPipPip
  • 34 posts
  • Advanced Member

Hello,

 

I have a dynamic physics object that is affected by gravity and therefore bounces against a static floor at the bottom of the screen. Since I want to simulate a very "bouncy" rubber ball, I have set the bounce value to 0.9.

 

The problem is that after a number of bounces when the speed should have been decreased to zero, it still keeps bouncing with very small movements and it never stops completely.

 

For various resaons, I cannot make the floor dynamic. The uggly solution would be to add a dynamic object one pixel high and with 0.1 alpha directly on the floor and let the ball bounce on that instead. This actually makes the ball stop after a number of bounces (as it should), but this has a negative side effect: when the ball stops, it does not rest on the floor, but instead hovers 1 pixel above it (due to the invisible dynamic object on it).

 

Ergo: what would be the proper solution to let a dynamic object bounce against a static object realistically?

 



[TOPIC: post.html]
#2

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,653 posts
  • Jedi

Hi @coronarocks,

This shouldn't vary between a static floor or a dynamic floor. You've set the bounce on the ball to 0.9, but have you set the bounce on the floor object to something other than default?

 

Take care,

Brent



[TOPIC: post.html]
#3

coronarocks

[GLOBAL: userInfoPane.html]
coronarocks
  • Starter
  • PipPipPip
  • 34 posts
  • Advanced Member

Hello Brent,

 

I have tried both leaving the floor bounce at default and also setting it to 0.0 but none of it helped: the ball never stops if it has a bouncing value of 9.0. However, I found something interesting...

 

Since the ball falls from the top of the screen to the bottom, the distance it falls is different acrross devices as the aspect ratio is different. On an iPad retina (with a low aspect ratio) it falls a short distance and if I set the ball bounce to maximum 8.5, the ball stops bouncing (as it should). However, on a device with a greater aspect ratio like the iPhone5, I need to decrease the ball bounce to 8.4 before the ball behaves correctly. This means that if I set it to 8.4 and someone is playing my game on a device with an even greater aspect ratio, the ball most probably will not bounce correctly. On the other hand, I am very reluctant to lower it even below 9.0 since the "mechanics" of the game requires that bounciness.

 

Again, adding that invisible 1 px layer on top of the floor causes the ball to bounce correctly regardless of how high I set the ball bounce. This is not an option , however, due to the reasons I wrote about above.

 

To me, all this feels like a bug in the physics engine. Or am I missing something?

 

Thank you for taking the time!



[TOPIC: post.html]
#4

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,653 posts
  • Jedi

Hi @coronarocks,

Which "scale" setting do you have the app configured for? letterbox, zoomEven, or zoomStretch? If you're not familiar with this topic, please refer to this guide for details:

http://docs.coronalabs.com/daily/guide/basics/configSettings/index.html

 

For bounce, the physics engine expects a maximum value of 1.0 for "realistic behavior". Setting it higher makes the ball almost fire back with a bouncy reflex, as if it's beyond realistic physical imagination in terms of restitution.

 

Brent



[TOPIC: post.html]
#5

coronarocks

[GLOBAL: userInfoPane.html]
coronarocks
  • Starter
  • PipPipPip
  • 34 posts
  • Advanced Member

Hello Brent,

 

Correction: I meant of course 0.95 and not 9.5, sorry for the confusion...

 

The setting I use is "letterBox". Just to rule out that this has anything to do with the issue, I just tried to change the setting to "zoomStretch" and "zoomEven", but it had no effect. Just to be clear: the only reason I mentioned the different devices was to show that the height from which the ball is dropped determines if the bouncing stops realistically or continues forever. The same logic applies if you drop the ball from different heights on any one device

 

Also, the highest value I have set the bounce value to is 0.95, never any higher since I want the ball to bounce realisitcally (and thus to stop eventually).

 

The problem remains: if you set the bounce at e.g. 0.95 for a dynamic object and let it fall (from a point high enough) against a static floor it nevers stops bouncing but keeps "jittering" on the floor forever. Please try this on e.g. iPhone5 and you will see that the ball actually never stops bouncing:

 

display.setStatusBar(display.HiddenStatusBar)
local Main = {}
local ball
local floor
local physics = require("physics")
physics.start()
function Main()
   
    ball = display.newCircle(100, 40, 10)
    physics.addBody(ball, "dynamic", { density=1, friction=0.3, bounce=0.95, radius=ball.width/2})
   
    floor = display.newRect(display.contentWidth/2, display.contentHeight - 5, 640, 10)
    physics.addBody(floor, "static")
   
end
Main()

 

Again, this seems like a bug to me since a realistic behavior would be for the ball to stop bouncing after a while. Or is there some other setting that needs to be set that I do not know about?



[TOPIC: post.html]
#6

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,653 posts
  • Jedi

Hi @coronarocks,

I see what you mean (testing it), and I think ultimately, with a bounce that high (0.95) you're going to get those results where it seems to jitter for a long time (or nearly forever). I typically never set my bounce parameter higher than around 0.6, and that I consider quite bouncy. Of course every scenario will differ a bit, but I think these are the expected results.

 

Best regards,

Brent



[TOPIC: post.html]
#7

coronarocks

[GLOBAL: userInfoPane.html]
coronarocks
  • Starter
  • PipPipPip
  • 34 posts
  • Advanced Member

Hello Brent!

 

I don't know if I agree that these are expected results... :)

 

If you add an invisible 1 px layer (dynamic) on top of the static floor it causes the ball to bounce correctly regardless of how high I set the ball bounce (see code below) As I said in a previous posting, howver, this is not an option here since the invisible layer will cause the ball to hover above the floor when resting.

 

How can the result be different depending on whether the floor is dynamic or static? Are you really sure this is not a bug? I mean, even the bounciest of balls should behave correctly/realistically for every value < 1.0. Or, the documentation should say something about that any value higher than 0.x may behave less correctly e.g. when bouncing.

 

 

require "CiderDebugger";
display.setStatusBar(display.HiddenStatusBar)
local Main = {}
local ball
local bounceFloor
local dynamicLayer
local physics = require("physics")
physics.start()
function Main()
   
    ball = display.newCircle(100, 40, 10)
    physics.addBody(ball, "dynamic", { density=1, friction=0.3, bounce=0.95, radius=ball.width/2})
   
    bounceFloor = display.newRect(display.contentWidth/2, display.contentHeight, 640, 10)
    physics.addBody(bounceFloor, "static")
   
    dynamicLayer = display.newRect(display.contentWidth/2, display.contentHeight - 10, 640, 1)
    dynamicLayer:setFillColor(1, 0, 0, 1)
    physics.addBody(dynamicLayer, "dynamic")
   
end
Main()



[TOPIC: post.html]
#8

Brent Sorrentino

[GLOBAL: userInfoPane.html]
Brent Sorrentino
  • Corona Staff
  • 4,653 posts
  • Jedi

Hi @coronarocks,

I did some testing and a quick search on Google, and it seems that bounce (restitution) cannot be considered as perfectly predictable in every situation, because there are so many factors in play. In your setup, you have the dynamic floor sitting atop the static floor, so perhaps there's some slight movement/friction that is occurring when these 3 bodies interact, and force isn't being transferred back to the same degree.

 

Unfortunately, I don't know the exact reason why this is occurring, and finding detailed answers on Box2D can be tricky, as its not too well-documented. You could post your question to the Box2D forums and hopefully Erin Catto (the creator) responds, or somebody who knows the precise reason for this. Otherwise, remember that Box2D is a simulation, prone to some oddities, and sometimes you just need to experiment with what "feels right" in your game.

 

Take care,

Brent



[TOPIC: post.html]
#9

coronarocks

[GLOBAL: userInfoPane.html]
coronarocks
  • Starter
  • PipPipPip
  • 34 posts
  • Advanced Member

Ok, thanks Brent!




[topic_controls]
[/topic_controls]



Also tagged with one or more of these keywords: physics, bouncing