I'm would like to achieve something like Object A will jump to position A in parabolic way. For example:

enter image description here

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.

  • \$\begingroup\$ do you need real physics or fake physics ? \$\endgroup\$ – Raxvan Jul 30 '14 at 14:01
  • \$\begingroup\$ What is the different between real physics and fake physics? which one is better? \$\endgroup\$ – tekminewe Jul 30 '14 at 15:17
  • \$\begingroup\$ "real" physics use Newton's laws of motion and take into account gravity, mass, and other forces. "Fake" physics is just a function that you write out of your head that looks good, something like 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) and Time 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\$ – Raxvan Jul 30 '14 at 15:35
  • \$\begingroup\$ Thank you for your explaination. Then how can I achieve that in real physics? \$\endgroup\$ – tekminewe Jul 31 '14 at 5:29

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

| improve this answer | |
  • \$\begingroup\$ Thank you for your answer, it's really work as I want, but still not so smooth like jumping. Maybe still need some value tweaking \$\endgroup\$ – tekminewe Jul 31 '14 at 5:31
  • \$\begingroup\$ Anytime. Re: smoothness, use the easing link I provided. Or create your own. You can theoretically do the same with the physics engine in SpriteKit, but this solution is much simpler, and likely just needs some easing to look realistic. What you might want to do is set up two paths (one with the first quadCurve, one with the second quadCurve) and use two different easing methods with both. \$\endgroup\$ – Attackfarm Jul 31 '14 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.