[Solved] Kinematic object not waking up my dynamic objects.

Post Reply
admiralnlson
Posts: 3
Joined: Fri Nov 11, 2016 7:29 pm

[Solved] Kinematic object not waking up my dynamic objects.

Post by admiralnlson »

Hi. Starting out with bulletPhysics (2.8 ), switching from PhysX.

I have a "kinematic camera", i.e. a no-mass btRigidBody set up like this:

Code: Select all

btKinematicCamera_->setCollisionFlags(btKinematicCamera_->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
[... and at every step: ...]
btKinematicCamera_->setWorldTransform(btTransform { to_bt(camera_.orientation()), to_bt(camera_.eyePosition()) });
as well as a bunch of (regular, dynamic?) rigid bodies with an initial randomized velocity, and a damping factor which makes them slow down over time.

When I bump the camera into the rigid bodies which are still moving, they move out of the way. Great. This is what I want.

But, at some point, some of the dynamic bodies reach a speed low enough for Bullet to assume they can be deactivated (as far as I understand).
And they don't collide with the camera (kinematic body) anymore. They remain inactive.

Is there something I can do to make the collision with a kinematic body wake them up?
Am I doing something wrong?

I've tried to use

Code: Select all

btRigidBody_.forceActivationState(DISABLE_DEACTIVATION);
on the dynamic objects. It does the job. But I'm thinking it might be less than ideal performance wise.

Thanks in advance.

EDIT: typos: Kinetic => Kinematic
Last edited by admiralnlson on Sat Nov 12, 2016 4:32 pm, edited 3 times in total.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: Kinetic object not waking up my dynamic objects.

Post by benelot »

Hi,

You mean a kinematic camera I think :) The thing is that kinematic objects are not meant to be moving by themselves. They are more like static, immobile things. You should create a rigidbody instead for your camera object. You could probably attach the rigidbody to the worldposition of the camera using a fixed constraint.Only a rigidbody activates other rigidbodies from their sleeping state. The other option would be to create a collision callback that tests if one of the collisions is with your camera object and the other object is sleeping, then activate it when the condition holds.
Link for thr second option: http://www.bulletphysics.org/mediawiki- ... d_Triggers
admiralnlson
Posts: 3
Joined: Fri Nov 11, 2016 7:29 pm

Re: Kinetic object not waking up my dynamic objects.

Post by admiralnlson »

Thanks for the reply.
You should create a rigidbody instead for your camera object.
My camera object is already a rigidbody (btRigidBody). Do you mean a non-kinematic one?
The thing is that kinematic objects are not meant to be moving by themselves.
What do you mean by that?
I understood the point of kinematic objects is exactly that.. They "move themselves" and affect other (non-kinematic) bodies. Otherwise what's the point of even adding them to the dynamic world?

I would understand if dynamic bodies collide with kinematic bodies either always or never.
But to me it's really an oddity that a dynamic body collides with kinematic objects, if it is awake. But doesn't get woken up by kinematic objects if it is asleep.

Is this really how the API is designed or am I missing something here?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Kinematic object not waking up my dynamic objects.

Post by drleviathan »

It sounds like your camera is already setup properly to be a kinematic btRigidBody. I think what you need to do is to manually activate the camera... whenever you actually change its translation -- that should activate any nearby objects.
admiralnlson
Posts: 3
Joined: Fri Nov 11, 2016 7:29 pm

Re: Kinematic object not waking up my dynamic objects.

Post by admiralnlson »

drleviathan wrote:I think what you need to do is to manually activate the camera... whenever you actually change its translation -- that should activate any nearby objects.
Nice!

I managed to fix it thanks to your reply. Although it was not the whole story.

I realize now that what I was experiencing until now was not proper collisions between my kinematic object and the dynamic objects.
The dynamic objects (when not sleeping) moved out of the way of the kinematic object, but were not getting actual impulses.

After adding at kinematic body creation time:

Code: Select all

btKinematicCamera_->activate(true);
And replacing my:

Code: Select all

pBtKinematicCamera_->setWorldTransform(btTransform { to_bt(camera_.orientation()), to_bt(camera_.eyePosition()) });
with:

Code: Select all

pKinematicMotionState_->setKinematicWorldTransform(btTransform { to_bt(camera_.orientation()), to_bt(camera_.eyePosition()) }); // KinematicMotionState based on last section of http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates
It's working perfectly now.

Thanks!

/closethread
Post Reply