Skip to main content
Clarified last sentence.
Source Link
Appeltaart
  • 430
  • 1
  • 4
  • 14

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

EDIT: This fix does however cause the object to go spinning wildly. In the didLoadFromCCB override I start a timer spawning these objects. Apparently, creating objects with physics while in this method doesn't end well. A proper workaround would be to call scheduleOnce with a delay of 0.1 andon a function to startapply the timer properangular velocity properly.

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

EDIT: This fix does however cause the object to go spinning wildly. In the didLoadFromCCB override I start a timer spawning these objects. Apparently, creating objects with physics while in this method doesn't end well. A proper workaround would be to call scheduleOnce with a delay of 0.1 and a function to start the timer proper.

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

EDIT: This fix does however cause the object to go spinning wildly. In the didLoadFromCCB override I start a timer spawning these objects. Apparently, creating objects with physics while in this method doesn't end well. A proper workaround would be to call scheduleOnce with a delay of 0.1 on a function to apply the angular velocity properly.

Explanation about didLoadFromCCB
Source Link
Appeltaart
  • 430
  • 1
  • 4
  • 14

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

EDIT: This fix does however cause the object to go spinning wildly. In the didLoadFromCCB override I start a timer spawning these objects. Apparently, creating objects with physics while in this method doesn't end well. A proper workaround would be to call scheduleOnce with a delay of 0.1 and a function to start the timer proper.

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.

EDIT: This fix does however cause the object to go spinning wildly. In the didLoadFromCCB override I start a timer spawning these objects. Apparently, creating objects with physics while in this method doesn't end well. A proper workaround would be to call scheduleOnce with a delay of 0.1 and a function to start the timer proper.

Post Undeleted by Appeltaart
Post Deleted by Appeltaart
Source Link
Appeltaart
  • 430
  • 1
  • 4
  • 14

The problem was in CCPhysicsBody.m. Upon instantiation the body's moment is 0, causing divide by zero errors, making the angular velocity NaN.

I fixed it by changing the function to the code below:

-(void)applyAngularImpulse:(CGFloat)impulse { if (_body.moment == 0) _body.angularVelocity += impulse; else _body.angularVelocity += impulse/_body.moment; }

Another error in my code was that arc4random_uniform returns an unsigned integer, thus creating very large numbers when going below 0. Casting to a signed integer solves that problem.