I'm trying to create a game using Apple's SpriteKit game engine.
While implementing some physics-based calculations in the game, I noticed that the calculated results differ from what effectively then happens to objects.
Example: calculating a body's trajectory through projectile motion's equations causes the body to actually fall down much sooner/quicker than what calculated.
How can I make the physics engine match the real-world physics laws when calculating something gravity-related?
I think I know what's going on with the sample code you have supplied on GitHub, which I'll reproduce here as questions on SO should contain the code:
What you've done is to:
subjectwith a physicsBody and placed it on screen with a initial velocity.inaccuratePositionnode, using Newton's laws of motion (v = ut + 1/2at²)accuratePositionnode, using Newton's laws of motionAll this is is
didMoveTo. When the simulation runs, the path of the nodesubjectfollows theaccuratePositionpath accurately.I think what's happening is that you are calculating the predicted position using subject's physicsBody's
velocity, which is in m/s, but the position is in points, so what you should do is convert m/s into point/s first.So what's the scale factor? Well from Apple's documentation here; it's.... 150 which is too much of a coincidence , so I think that's the problem.
Bear in mind that you set the vertical velocity of your object to 700m/s - that's 1500mph or 105000 SK point/s. You'd expect it to simply disappear out through the top of the screen at high speed, as predicted by your red path. The screen is somewhere between 1,000 and 2,000 points.