Trajectory Prediction Very Laggy

I'm trying to make a Gravity Simulation for an upcoming game. It's been going smoothly so far, exempting the trajectory prediction, which is so slow I had to bind it to a key (m).

I know that I need to decrease the resolution, but I don't know how.

The program is called Project Δ.

You replaced the proper expressions of gravity force and acceleration with random constants that give you a pleasant visual effect.

$$ (force) F = G \frac{m M}{R^2}$$
$$ (acceleration) a= \frac{F}{m} \implies a= G \frac{M}{R^2}$$ where G*M = const
$$ \Delta v = a \Delta t $$

The lower the $$\Delta t$$ the bigger the resolution (precision) of the simulation.
But simulation is played at 60 steps per second, so the perceived slowness.
With a few steps of simulation warped together, the animation looks faster without losing the precision.

What would that look like in Snap! code?

(The lag is most noticeable with a large orbit. Like this:
Screen recording 2024-01-09 19.12.56
)

(I'm probably missing something simple in your response. Thank you for your time.)

Gravity Sim script pic mass of the central body x gravity coeff
Gravity Sim script pic (1) time advance per step, resolution
Gravity Sim script pic (2) frames skipped, animation speed
Sim :link:

You could try to move the code to the "Ship" sprite, so you won't need to use ASK and TELL any more. These blocks require extra execution time.

Does this help?

It doesn't cause the kind of lag I'm talking about here, but that is a nice tip.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.