Reputation: 25
I am trying to move a Sprite from a 'shooting' node on the scene to a dynamic but known point on the scene using an arc.
For context it is a tower defence game and this is the 'mortar' tower.
I am using SpriteKit and Objective-C. I am relatively new to coding but I'm pretty far down the line so I have a fair grip on things, it has just been very long since I have used trigonometry and I'm suffering with the UIBezierPath.
Here is a snippet of my code:
CGPoint cannonPointOnScene = [self.scene convertPoint:self.position fromNode:self.parent];
CGPoint originPoint = CGPointMake(realDest.x - cannonPointOnScene.x, realDest.y - cannonPointOnScene.y);
float angle = atan2f(originPoint.y, originPoint.x);
UIBezierPath *testPath = [[UIBezierPath alloc] init];
[testPath addArcWithCenter:CGPointMake(self.position.x , self.position.y) radius:10.0 startAngle:0.0 endAngle:angle clockwise:YES];
SKAction *actionMove = [SKAction followPath:[testPath CGPath] speed:self.projectileSpeed];
SKAction * actionMoveDone = [SKAction removeFromParent];
SKAction* fire = [SKAction sequence:@[actionMove, actionMoveDone]];
Using that code, I just get my projectile appearing in one spot, quite far from the tower node, then removed from the scene.
Thanks in advance!
Upvotes: 0
Views: 568
Reputation: 581
I can't comment yet so I can't ask for more information before attempting to provide an answer, but I still think I can help.
I can't tell from your variables how exactly you're constructing you path relative to your sprites but the first thing I'd suggest is to increase your radius to 100.0 or 200.0 just to see what's happening. 10.0 is a pretty small radius. The boilerplate gameScene is 1024 points wide, 10.0 points is less than 1% of that.
The path you're creating is a portion of a circle centred around "self.position" with a radius of 10 points.
Given your description and assuming we just use the scenes coordinate space, I think:
The above suggestions presume a lot about how your game functions and it's very unlikely any of it works, but hopefully it gives you a good idea of where to start.
Upvotes: 1