# Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for
Show  only  | Search instead for
Did you mean:
Level 11

## Re: Elastic Collision Ball Physics

"Romans_I_XVI" wrote:
Roku 3, if I do that on Roku 1 it's very laggy.

How many FPS on #42xx vs #3xxx vs 27xx?

Doing the elastic collision of round particles should be simple - admittedly i haven't done it in years but https://en.wikipedia.org/wiki/Elastic_c ... _Newtonian

The "pass trought" and "drag along" are interesting issues of simulation discretization to frames which i seem to vaguely remember. Your method of "back off" correction - does it work well when there is bunch of objects touching at the same time? For example line of balls like in Newton's craddle (no need of wires, end balls may bounce back from the room walls).

Alternatively, how about counting collision between two bodies only when they are touching (or overlapping) AND their speed vectors are colliding? (I.e. when they are pulling apart that's not collision or both are moving same direction and frontmost is faster, that's also not)
Level 9

## Re: Elastic Collision Ball Physics

Hey EnTerr, the "back off" method is working very well. I even added gravity and friction and the balls all eventually settled with no issues. 😄
Level 11

## Re: Elastic Collision Ball Physics

Well if you add enough friction, all issues will be settled sooner than later 😄
Looks quite neat, i share your enthusiasm!
W/o friction/gravity - it's a screen saver. With - it made me think of those sand picture frames - where you flip and watch sand grains settle down in water.

Don't you have something to track frames-per-second? I find it quite useful, but doing it right can be tricky. Here is what i do now (sorry for copying Lua, don't have my B/S handy but is trivial to adapt):
`FPS_label = director:createLabel {  vAlignment = "top", hAlignment="right",   textXScale = 2,     textYScale = 2,  textBorderTop = 30, textBorderRight = 70,  color = FONT_COLOR, zOrder = 100,  text = ''}scene:addChild(FPS_label)avg_deltaTime = 0.03  -- start value, unimportanttime_to_next_report = 0function update_fps()  avg_deltaTime = (19 * avg_deltaTime + system.deltaTime) / 20    -- keep running average  time_to_next_report = time_to_next_report - system.deltaTime      if time_to_next_report <= 0  then    time_to_next_report = 1 -- every 1 second    local fps = string.format(avg_deltaTime > 0.101 and '%.1f' or '%.0f', 1/avg_deltaTime)    FPS_label.text = fps  end    end`
The interesting parts are keeping (exponential) moving average to stabilize the value - and updating the displayed text less often than every frame (for humane reasons)