2D orbital physics

前端 未结 2 1470
面向向阳花
面向向阳花 2021-02-02 15:55

I\'m working on a 2D physics engine for a game. I have gravity and masses working, using a simple iterative approach (that I know I\'ll have to upgrade eventually); I can push t

相关标签:
2条回答
  • 2021-02-02 16:01

    You need to make sure that your delta t iterative time value is small enough. You will definitely have to tinker with the constants in order to get the behaviour you expect. Iterative simulation in your case and most cases is a form of integration where errors build up fast and unpredictably.

    0 讨论(0)
  • 2021-02-02 16:23

    Yes, these equations hold in 2D space, because your 2D space is just a 2D representation of a 3D world. (A "real" 2D universe would have different equations, but that's not relevant here.)

    A long shot: Are you perhaps using distance to the surface of the planet as r?

    If that isn't it, try cutting your time step in half; if that makes a big difference, keep reducing it until the behavior stops changing.

    If that makes no difference, try setting the initial velocity to zero, then watching it fall for a few iterations and measuring its acceleration to see if it's GM/r2. If the answer still isn't clear, post the results and we'll try to figure it out.

    0 讨论(0)
提交回复
热议问题