0

I have a SKSpriteNode that represents the user and I'd like this node gets move with the user movement, if the user walks then the node moves in the same direction.

The start position is the center of the view and I think it's possible to make this works with rotationRate, userAcceleration and gravity from CMMotionManager (iOS 7) but I don't know if I'm wrong or what operations I should do with these values.

I appretiate if someone could help me.

Thanks.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • can you show what you've tried so far, and what results that has given you? – mc110 Jun 16 '14 at 21:51
  • You can find a good tutorial for using the accelerometer with SpriteKit here: http://code.tutsplus.com/tutorials/build-an-airplane-game-with-sprite-kit-project-setup--mobile-19891 – ZeMoon Jun 17 '14 at 09:48

1 Answers1

0

Now, I'm do

if ([self.motionManager isDeviceMotionAvailable] == YES) {
            [self.motionManager startDeviceMotionUpdatesToQueue:self.queueMotion withHandler:^(CMDeviceMotion *motion, NSError *error) {
                self.xpos = motion.userAcceleration.x * motion.gravity.x * motion.rotationRate.x;
                self.ypos = motion.userAcceleration.y * motion.gravity.y * motion.rotationRate.y;

                [self performSelectorOnMainThread:@selector(updatePosition:) withObject:nil waitUntilDone:YES];
            }];
        }

Then I add these x and y coordinates to the SKSpriteNode position and I move the SKSpriteNode to this final position. What I am getting is that the SKSpriteNode doesn't get move while I'm walking but if I make a hard acceleration it moves but just a moment, if I'm walking with a constant velocity it doesn't get move.