I’ve made a very simple and primitive JavaScript canvas engine that is simply not dependent on time, as in it assumes that t = 1 in the formula v = u + at - v is the current velocity, u the initial velocity and a is acceleration due to gravity.

Now, the issue with this method is that if the value of gravity, or velocity is large enough that the object it should collide, it just goes right through it. Now, I have been told that if time was a parameter, we could just increase the frame rate and dilate the time to resolve this, but this would mean that the engine would no longer be deterministic - as in, the simulation would not work out the exact as it we assumed it to be, owing to hardware and software requirement like decimal point handling and precision.

How can we deal with this issue on this simple deterministic engine, and improve collision detection?

  • LalSalaamComrade@lemmy.mlOP
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    4 days ago

    Accuracy does not really matter here - it should be fast. But there has to be no compromise on collision. Gravity is constant, but it may change - not a strong requirement for now.

    • deegeese
      link
      fedilink
      arrow-up
      2
      ·
      4 days ago

      Compute the bounding volumes of the objects during the step. If the bounding volumes intersect, it’s a possible collision.

      You can then use a root finder such as bisection to determine if, and at what position and instant the objects collide. This is slow so you only want to do it for pruned object pairs.

      If gravity varies during the simulation, you would need to use a dynamic time step and the problem is a lot harder.