My goal is to have a formula which, given the three inputs below, generates the necessary CGVector to put an SKPhysicsBody in perfect circular orbit around a gravity field.
Inputs:
- the gravity field's Strength can vary
- the orbiting SKPhysicsBody's Mass can vary
- the orbiting SKPhysicsBody's distance from the gravity field can vary
I have a test program set up to try to find some constants within SKSpriteKit that will help me come up with a formula. In this test program, I do the following:
- create a gravity field in the middle of the viewing area with a Strength of 1
- create an SKPhysicsBody with a Mass of 1
- place the SKPhysicsBody at a certain distance from the gravity field
Through trial-and-error, I find the appropriate ApplyImpulse CGVector that puts the body into a near-perfect circular orbit. After the ApplyImpulse, I calculate the body's distance from the gravity field inside the "Update" method.
But what I am finding is that given the EXACT same inputs, results can vary literally from one attempt to the next. It's very bizarre. The differences aren't huge, but I would think that with all inputs the same, the results would be the same.
Is there some unknown random element to the SpriteKit when it comes to gravity and impulses?