I am creating a game that simulates a to-scale version of the solar system in 2D. It allows the user to build and fly rockets around the solar system. However, I am having an issue with position values in the coordinate spaces of each SKNode.
When I try to change a position value of an object that is very far from the origin (around 1,000,000 coordinate spaces or more away in either the x or y axis), the position value is changed slightly. However, the farther from the orgin an node gets, the more this value gets changed.
This function calculates the next position of a planet, and then updates the position of the planet object:
func updatePos(delta:CGFloat, ct:CGFloat){
let t = ct.truncatingRemainder(dividingBy: T)
let newPos = getPos(at: t)
prevPos = position
self.position = newPos
self.vel = calcVel()
if(self.objectName == "Earth"){
print("Earth P1: \(newPos.dictionaryRepresentation)")
print("Earth P2: \(self.position.dictionaryRepresentation)")
}
}
}
The output here should print the same value. But once I assign my calculated position value to the position of a planet, the value is changed as shown here:
Earth P1: {
X = "-146973645921.7216";
Y = "6187141860.840587";
}
Earth P2: {
X = "-146973638656";
Y = 6187141632;
}
Earth P1: {
X = "-146973645295.3229";
Y = "6187156989.44586";
}
Earth P2: {
X = "-146973638656";
Y = 6187156992;
}
This issue is happening with the SKCameraNode as well. The farther from the origin the position of the camera gets, the choppier the movement of the camera becomes. It also becomes very noticible the more the camera zooms in, as show here:
https://gfycat.com/HighScarceHorsemouse
I have tried so many different things to fix this issue. I have tried to use SKActions to move the objects around instead. This did not fix the issue.
One thing to note: The camera choppyness only happens when its position values become very large. When the camera is near (0, 0) of the SKScene I have no issues with choppyness. This could possibly be an issue with either the position values of SKNodes, or maybe an issue with the coordinate spaces of the scene and the nodes themselves.
The documentation for an SKScene describes a scene as being "infinitely large," so I feel like a scene of this size shouldn't be causing these problems.
Any insight into what this may be would be extremely helpful.