How do I get a SKNode
to move forward?
I\'ve been able to get the node to move in a fixed direction using [SKAction moveByX:y:duration:]
bu
I have thought about this as well. I want to make a node that can seem to be turning before proceeding. One way I have considered doing this is to have a child node attached the the "forward-most" portion of the node that is moving in the scene. Then I would calculate the distance of the tap form the child node. Does that make sense? Essentially, I would be able to calculate the front of the node from a tap anywhere in the scene.
This will rotate, then towards where you tap
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInNode:self];
CGPoint diff = CGPointMake(location.x - _myPlayer.position.x, location.y - _myPlayer.position.y);
CGFloat angleRadians = atan2f(diff.y, diff.x);
[_myPlayer runAction:[SKAction sequence:@[
[SKAction rotateToAngle:angleRadians duration:1.0],
[SKAction moveByX:diff.x y:diff.y duration:3.0]
]]];
}
}
}