I can't really give you testbed as the game currently has allot of artwork.
I've commented out all my player update code ( weapons switching, chat etc ) other than this and I still get the problem:
Code:
void CEntitySoldier::Simulate( float dt, unsigned int callTime )
{
b2Vec2 centerOfMass;
b2Vec2 force;
if ( p_Body->GetPosition().x != p_Body->GetPosition().x && !isNan ) {
printf( "(CEntitySoldier::Simulate)Error: isNan \n" );
isNan = true;
}
if ( input.up ) {
force.Set( 0, -750 );
p_Body->ApplyForce( force, centerOfMass );
} else if ( input.down ) {
force.Set( 0, 750 );
p_Body->ApplyForce( force, centerOfMass );
}
if ( input.left ) {
force.Set( -750, 0 );
p_Body->ApplyForce( force, centerOfMass );
} else if ( input.right ) {
force.Set( 750, 0 );
p_Body->ApplyForce( force, centerOfMass );
}
p.FromB2VEC2( p_Body->GetPosition() );
v.FromB2VEC2( p_Body->GetLinearVelocity() );
}
"input" is just a class that holds player button data as booleans.
Here is the construction code for the players physics data:
Code:
userData.entity = this;
userData.object = false;
b2BodyDef p_BodyDef;
p_BodyDef.position.Set( p.x, p.y );
p_BodyDef.linearDamping = 9;
p_BodyDef.fixedRotation = true;
p_BodyDef.userData = &userData;
p_Body = world->CreateBody( &p_BodyDef );
b2CircleDef s_ShapeDef;
s_ShapeDef.radius = 1.5f;
s_ShapeDef.density = 1;
p_Body->CreateShape( &s_ShapeDef );
p_Body->SetMassFromShapes();
The object it is colliding with ( Well sometimes, it also sometimes just NaN's out without touching anything ) is a tree and here is its physics data:
Code:
b2BodyDef p_BodyDef;
p_BodyDef.position.Set(p.x, p.y);
p_BodyDef.userData = &userData;
p_Body = a->spc->world->CreateBody( &p_BodyDef );
b2CircleDef p_ShapeDef;
p_ShapeDef.radius = 1.5f;
p_ShapeDef.density = 0;
p_Body->CreateShape( &p_ShapeDef );
p_Body->SetMassFromShapes();
If i just leave the player controls alone when it starts up, its fine for a bit. I can run around and stuff, but then it will randomly NaN out again :/ i've never had this problem before.