Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 19, 2017 2:20 am 
Offline

Joined: Wed Apr 19, 2017 2:08 am
Posts: 3
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:

Code:
...
float32 dt = 1.0f / 1000.0f;
void Scene::tick(const float32 elapsedTime)
{
        dynamicsWorld_->stepSimulation(dt, 10);
}
...


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:

Code:
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;
    }
}


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.


Top
 Profile  
 
PostPosted: Wed Apr 19, 2017 4:23 am 
Offline

Joined: Wed Apr 19, 2017 2:08 am
Posts: 3
Well, it turns out I was creating my rigid bodies at (0, 0, 0), and then trying to reposition them by changing the world transform. If I set the initial position of the rigid body when I create it to be (5, 0, 0), everything works as expected.

I did some googling around how to move rigid bodies, and it seems there's not a definitive solution on how this is done? I've read some places that say you can't really do it and you need to remove and re-add the rigid body, whereas some say you can set the world transforms (As I've done).

Is there a definitive answer on how I can move a rigid body ( without applying force to it)?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group