Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

lag, deltaTime & box2d - any advice?
Started by craig.stowers Apr 30 2019 10:17 PM

2 replies to this topic
delta time physics framerate lag
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

craig.stowers

[GLOBAL: userInfoPane.html]
craig.stowers
  • Observer

  • 28 posts
  • Corona SDK

So I'm fairly confident with my understanding of delta time and modifying movement so objects get around in respect to time instead of frames. I've applied this to my "handcrafted" physics with good results

To apply this to box2d physics do I just run something like the following on an enterFrame listener?
 

physics.setTimeScale(deltaTime)

 

Or maybe Box2d is already configured in some way to manage time based movement?
I found with the line above things maybe seem more "jerky"...

Thanks in advance - I did have a quick look around but couldn't find too much relevant information.



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 762 posts
  • Corona SDK

All that physics.setTimeScale() does is adjust the speed at which the physics simulation runs. 

What you want is https://docs.coronalabs.com/api/library/physics/setTimeStep.html 

 



[TOPIC: post.html]
#3

craig.stowers

[GLOBAL: userInfoPane.html]
craig.stowers
  • Observer

  • 28 posts
  • Corona SDK

All that physics.setTimeScale() does is adjust the speed at which the physics simulation runs. 

What you want is https://docs.coronalabs.com/api/library/physics/setTimeStep.html 

 

 

Thanks I have just been playing with that... I presume it's not something you just set once and leave it to Box2d.When I update it every frame based on delta... yes it keeps things moving relatively normal even when I overload the engine.

However just when things would otherwise be smooth sailing, using the setTimeStep seems to create a pretty jerky result. For instance after I simplify the scene down until it's buttery smooth.... messing with setTimeStep every frame seems to have a detrimental effect. It's only slight but noticeable. Weird.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: delta, time, physics, framerate, lag