Hey everyone,
I have been looking into moving objects in bullet, but I can't seem to get it to work (perhaps I am misunderstanding the concept of motion states). Outside of trying to hack together a motion state, I have tried to applyForce(), etc. but nothing seems to work. Basically, I'm working on a demo (I've never used bullet before) using the irrlicht rendering engine. I have created a btBoxNode and set it to an irrlicht-rendered cube. Initially, it is above the map and falls properly (default motion state - yes?), however, I am unable to move it in any direction - can anyone shed some light on this issue?
-RageD
EDIT: Just another thing to mention: it seems if I move it BEFORE it hits the level mesh, I can move it. However, the moment it collides with the ground (a GImpactMesh - I have read that I should use btBvhTriangleMesh, however, I'm getting a higher FPS with GImpactMesh) it gets stuck. Any thoughts?
Moving Objects
-
- Posts: 237
- Joined: Tue Jun 29, 2010 10:27 pm
Re: Moving Objects
One common reason is that if an object comes to rest for a certain period of time (offhand I don't recall the default) it becomes inactivated by the physics engine for efficiency reasons. The only way to have it react to manually applied forces once its deactivated is to manually reactivate it:
I think you would call this right before you apply the force. Might work if you call it right after as well (since I'm guessing it just sets a flag and all of this is registered/acknowledged on the next bullet simulation tick).
Alternatively, your object may indeed be getting "stuck". First, try increasing the magnitude of your force. Second, check the friction settings on your object and the ground. If they both have full friction, it may be stopping your object from moving along the ground (or you could just apply a really strong force in the "up" direction, which would avoid any friction issues). Finally, if turning off friction doesn't work, and you notice some unstable jittering when you try to apply the force, then it could be that somehow your object is getting stuck in the ground geometry.
Code: Select all
rigidBody->activate() // or rigidBody->activate(true)
Alternatively, your object may indeed be getting "stuck". First, try increasing the magnitude of your force. Second, check the friction settings on your object and the ground. If they both have full friction, it may be stopping your object from moving along the ground (or you could just apply a really strong force in the "up" direction, which would avoid any friction issues). Finally, if turning off friction doesn't work, and you notice some unstable jittering when you try to apply the force, then it could be that somehow your object is getting stuck in the ground geometry.
-
- Posts: 2
- Joined: Sat Jun 11, 2011 4:33 pm
Re: Moving Objects
Perfect, thanks for your help (I was unaware of the efficiency deactivation). So will this work, rather than making constant calls (this is for my "player" box, so I never want it deactivated)
-RageD
Code: Select all
body->setActivationState(4); // Disable deactivation - yes?
-
- Posts: 237
- Joined: Tue Jun 29, 2010 10:27 pm
Re: Moving Objects
Yes that would/should do it as well (good to know; I wasn't aware of that function
), and would save you calls to activate() every time you want to apply a force. As a general rule, it's good to let objects "fall asleep" if they are not in motion, otherwise they are constantly checked for collisions even when motionless (and thus not going to be causing any new collisions). Though if performance is/won't be a problem for your purposes, then it shouldn't matter.
To see the effect of sleeping/activation, drop a large pile of boxes on a surface and watch the frame rate drop as they all collide, speed up again when they all fall asleep, and then drop again if any new collisions cause them to "wake up" (which usually results in a chain reaction of all touching objects getting woken up).

To see the effect of sleeping/activation, drop a large pile of boxes on a surface and watch the frame rate drop as they all collide, speed up again when they all fall asleep, and then drop again if any new collisions cause them to "wake up" (which usually results in a chain reaction of all touching objects getting woken up).