简体   繁体   中英

How to move “obstacle” objects. Corona SDK Physics Box2D. Physics Update?

I'm trying to understand the proper way to move "obstacle" objects in corona/box2d. I want to know how to write my code so that the movement is deterministic and in-step with the physics engine. Is this possible?

I'm familiar with Unity which has a physics update (FixedUpdate). Where you can add a bit of code to execute on every physics step. This keeps the physics deterministic, frame and system time independent.

For example, in my game I want to do things like: Make a platform that moves back and forth, make an object that scales up and down in size. I would still like the physics to work properly and allow the ball in my game to bounce off of these for example. Depending on the case, I imagine that I should use either kinematic or dynamic bodies .

I've searched around and the way to periodically manipulate these objects is to use:

  • timer.performWithDelay . But this has an issue mentioned in the docs "Timers run on system time. If the app is suspended, running timers will not be automatically paused"
  • Listening to an enterFrame event. But this has a similar issue, if the frame rate drops then the object won't be moved enough. We can use delta time to deal with this, but this has determinism issues (moving an object too much on a lag spike).
  • transition.to . I'm guessing this is implemented with timer.performWithDelay and has the same issues.

I don't think that any of these will behave deterministic. Any suggestions? Thanks for the help.

You should really use:

object:setLinearVelocity(xVelocity, yVelocity)

or

object:applyForce(xForce, yForce)

instead of transition.to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM