0

I have a scene with one physical body.

self.player.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.player.size.height / 2];
self.player.physicsBody.dynamic = YES;
self.player.physicsBody.allowsRotation = NO;
self.player.physicsBody.mass = 1;
[self addChild:self.player];

The gravity is set to be -9.8:

self.physicsWorld.gravity = CGVectorMake( 0.0, -9.8 );

I try to check if that's true:

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
    double delta = currentTime - _pasttime;
    _pasttime = currentTime;
    float ax = (self.player.physicsBody.velocity.dx-self.oldVelocity.dx)/delta;
    float ay = (self.player.physicsBody.velocity.dy-self.oldVelocity.dy)/delta;
    self.oldVelocity = self.player.physicsBody.velocity;
    NSLog(@"The acceleration is: %f %f",ax,ay);
}

And I get the following output:

2014-04-10 17:12:12.469 PhysicsTest[4508:60b] The acceleration is: 0.000000 -413.161133
2014-04-10 17:12:12.485 PhysicsTest[4508:60b] The acceleration is: 0.000000 -1732.006226
2014-04-10 17:12:12.502 PhysicsTest[4508:60b] The acceleration is: 0.000000 -829.603760
2014-04-10 17:12:12.518 PhysicsTest[4508:60b] The acceleration is: 0.000000 -860.666260
2014-04-10 17:12:12.534 PhysicsTest[4508:60b] The acceleration is: 0.000000 -831.616455
2014-04-10 17:12:12.568 PhysicsTest[4508:60b] The acceleration is: 0.000000 -514.745300
2014-04-10 17:12:12.585 PhysicsTest[4508:60b] The acceleration is: 0.000000 -1667.948853
2014-04-10 17:12:12.601 PhysicsTest[4508:60b] The acceleration is: 0.000000 -839.192383
2014-04-10 17:12:12.618 PhysicsTest[4508:60b] The acceleration is: 0.000000 -807.683167
2014-04-10 17:12:12.651 PhysicsTest[4508:60b] The acceleration is: 0.000000 -523.592285

What the hell?

João Abrantes
  • 4,772
  • 4
  • 35
  • 71
  • What result were you expecting? – sangony Apr 10 '14 at 16:32
  • @sangony 2014-04-10 17:12:12.469 PhysicsTest[4508:60b] The acceleration is: 0.000000 -9.8 repeated over and over again.. – João Abrantes Apr 10 '14 at 16:33
  • Maybe I am completely missing your point here... are you saying that the acceleration curve is incorrect on your player? – sangony Apr 10 '14 at 16:44
  • @sangony I should just have a falling object. Falling with a constant accelaration, the gravity accelaration -9.8. I get instead a non constant accelaration with strange values very different from -9.8.. – João Abrantes Apr 10 '14 at 16:59
  • I ran your code myself. I had a 1x1 sprite with standard properties. It appears that the further away from the visible screen the object falls, the slower its velocity. My sprite's velocity started out with -18523 and about 50 seconds later the velocity had dropped to -7. I can only assume that the physics engine is built to pay less attention to objects the further away they get from the actual viewing area which makes sense. Why would you want to spend processor cycles on an object that's 50,000 points away from the visible area? It's an explanation, not an answer. – sangony Apr 10 '14 at 22:24

0 Answers0