0
votes

How does SpriteKit's physics engine (Box2d) move bodies and apply gravity to them? is it just the standard:

velocity = velocity + gravity
position = position + velocity * deltaTime

or is there a more complex equation.
I ask this because I am trying to calculate the trajectory of the body and plot it.

1
velocity = velocity + gravity * deltaTime - 0x141E

1 Answers

0
votes

Simplified, this is correct. However there can be other forces acting on a body (collisions, joints) and thresholds (ie stop moving if velocity below threshold, etc) and floating point rounding errors can add up.

So if you're looking for a forward calculation it depends on how precise it needs to be.

The most precise option would be to actually run the simulation to advance it to see where bodies will be - however since SK doesn't give you the Box2D sources this can't be done, ie you can't copy the world state and advance it manually in a copy of the current world.