I'm trying to manipulate an object. When it gets near another object, let's say a globe, I want the globe to have a gravitational pull on the original object. I know I'm supposed to use CCBezierTo
, so this isn't so much a programming question as it is a math question.
Mathematically, how could I figure out the three points of the bezier curve (1, 2, and end) and give it a weight depending on its distance (further away = less pull). I already have the distance mapped out in a variable.
Think of a spaceship slingshotting around the moon.
Code:
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(projectile.position.x + 10, projectile.position.y + 20);
bezier.controlPoint_2 = ccp(projectile.position.x + 20, projectile.position.y + 40);
bezier.endPosition = ccp(projectile.position.x + 30, projectile.position.y+60);
id bezierAction = [CCBezierTo actionWithDuration:1 bezier:bezier];
[projectile stopAllActions];
[projectile runAction: bezierAction];