Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
do you need real physics or fake physics ? –  Raxvan Jul 30 at 14:01
    
What is the different between real physics and fake physics? which one is better? –  miniram Jul 30 at 15:17
    
"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 –  Raxvan Jul 30 at 15:35
    
Thank you for your explaination. Then how can I achieve that in real physics? –  miniram Jul 31 at 5:29

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
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 –  miniram Jul 31 at 5:31
    
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. –  Attackfarm Jul 31 at 5:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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