SKAction move forward

How do I get SKNode to move forward?

I managed to get the node to move in a fixed direction using [SKAction moveByX:y:duration:] , but I want it to move in a direction relative to its direction.

I want to make each node rotate 45 degrees, then "walk" forward 50 pixels.

It seems simple enough, I just can't find it.

+2
source share
2 answers

It will rotate and then to where you click

 -(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.xy:diff.y duration:3.0] ]]]; } } } 
+2
source

I also thought about it. I want to make a node that might seem turning before proceeding. One of the ways that I have considered is to have a child element of a node associated with the forward-most part of the node that moves in the scene. Then I would calculate the distance from the tap from the child node. Does this make sense? Essentially, I could calculate the front of the crane node anywhere in the scene.

0
source

Source: https://habr.com/ru/post/955640/


All Articles