I'm would like to achieve something like Object A will jump to position A in parabolic way. For example:
I am able to make the object jump but i do not know how to calculate to make the object jump to the precise location.
SpriteKit uses SKAction
objects to accomplish most of its functionality. What you're seeking is SKAction's
followPath:duration:
action.
The following accomplishes this:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointZero];
[path addQuadCurveToPoint:CGPointMake(deltaX/2, desiredHeight) controlPoint:CGPointMake(0, desiredHeight)];
[path addQuadCurveToPoint:CGPointMake(deltaX, deltaY) controlPoint:CGPointMake(deltaX, desiredHeight)];
CGPathRef pathref = path.CGPath;
[jumpingNode runAction:[SKAction followPath:pathref duration:desiredDuration]];
This allows the Node to move along the specified path. It looks very uniform, but you can always add easing (related StackOverflow question) to give a more natural look
f(x) = sin( pow(x,0.5f) * Pi);
. Consider having point A and B and you want to jump ObjectA from A to B =>ObjectA.position = lerp(A,B,Time) + Vector.Up * f(Time)
andTime
is from 0 to 1. No approach is better than the other, "fake" physics can look better or worse , it all depends on your imagination \$\endgroup\$