Rigid body starting position reset to origin sometimes
Posted: Wed Apr 19, 2017 2:20 am
Hi,
I've got a basic physics simulation running, and it seemed to be working well, other than I noticed that most of my rigid bodies were starting off at position (0, 0, 0) instead of the position I set, which was (5, 0, 0). I verified after I added the rigid body ( via a call to `motionState->getWorldTransform().getOrigin();`) That the initial position is in fact correct.
Sometimes, however, the rigid bodies would actually start at the correct position I set. I eventually started to see that when I ran the physics engine like this:
All of my entities started to show up in the correct position.
However, if I tick the physics simulation in a way that tries to reflect the actual elapsed time, Like so:
Most of the entities would spawn At the origin (i.e. not at the correct position).
In both scenarios, the dynamics world is getting the exact same Delta Time value, it's just that in one case sometimes it doesn't get called if enough time has elapsed.
Does this make sense to anyone? I'm really not sure what I'm doing wrong.
I've got a basic physics simulation running, and it seemed to be working well, other than I noticed that most of my rigid bodies were starting off at position (0, 0, 0) instead of the position I set, which was (5, 0, 0). I verified after I added the rigid body ( via a call to `motionState->getWorldTransform().getOrigin();`) That the initial position is in fact correct.
Sometimes, however, the rigid bodies would actually start at the correct position I set. I eventually started to see that when I ran the physics engine like this:
Code: Select all
...
float32 dt = 1.0f / 1000.0f;
void Scene::tick(const float32 elapsedTime)
{
dynamicsWorld_->stepSimulation(dt, 10);
}
...
However, if I tick the physics simulation in a way that tries to reflect the actual elapsed time, Like so:
Code: Select all
float32 dt = 1.0f / 1000.0f;
float32 accumulator = 0.0;
void Scene::tick(const float32 elapsedTime)
{
accumulator += elapsedTime;
while ( accumulator >= dt )
{
dynamicsWorld_->stepSimulation(dt, 10);
accumulator -= dt;
}
}
In both scenarios, the dynamics world is getting the exact same Delta Time value, it's just that in one case sometimes it doesn't get called if enough time has elapsed.
Does this make sense to anyone? I'm really not sure what I'm doing wrong.