So I have a SKSpriteNode, and its supposed to be dragged from the middle of the screen, let go, then smoothly flow to the nearest corner (or rather, 10 points away on each axis from the nearest corner).
I use a method that should return a CGPathRef with an origin at the node's location, that starts off at the angle provided, (the nodes angle off center), then curves toward the end corner, ending at the end corner (all relative to the node's location...), for a smooth transition between the user's drag and the program's drag completion. The method is as follows:
-(CGPathRef)createPathToEndpoint:(int)end from:(CGPoint)start atAngle:(float)Angle{
UIBezierPath *path = [[UIBezierPath alloc]init];
[path moveToPoint:CGPointZero];
//Code to set up endPoint
CGPoint translatedEndPoint = CGPointMake(endPoint.x-start.x, endPoint.y-start.y);
CGPoint cP1;
/*
Code here to set cP1 for desired path attributes.
Not included for simplicity's sake, because what really seems to be the issue is
translatedEndPoint not seeming correct.
*/
[path addQuadCurveToPoint:translatedEndPoint controlPoint:cP1];
CGPathRef newPath = [path CGPath];
return newPath;
}
The SKSpriteNode is made to follow that path through the following code:
CGPathRef rollPath = [self createPathToEndpoint:section
from:[touch locationInNode:self]
atAngle:angle];
NSTimeInterval timeMove = MIN((timePassed/[self distanceBetween:mainBall.position and:middle])*100,1);
SKAction *move = [SKAction followPath:rollPath
asOffset:YES
orientToPath:NO
duration:timeMove];
But when the code runs, the sprite will generally end up some distance away from the end point, anywhere from a couple to probably upwards of 30 points away, even. What gives?