Is it possible to turn a Kinematic Rigidbody to a Dynamic?!
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Is it possible to turn a Kinematic Rigidbody to a Dynamic?!
I have a Kinematic Rigidbody and im setting it
kinebody->setCollisionFlags(kinebody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
kinebody->setActivationState(DISABLE_DEACTIVATION);
Then when i want to turn it into a dynamic im calling this
kinebody->forceActivationState(ACTIVE_TAG);
What exactly am i doing wrong here!
kinebody->setCollisionFlags(kinebody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
kinebody->setActivationState(DISABLE_DEACTIVATION);
Then when i want to turn it into a dynamic im calling this
kinebody->forceActivationState(ACTIVE_TAG);
What exactly am i doing wrong here!
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
You need to remove the [/b]CF_KINEMATIC_OBJECT[/b] flag to make the object dynamic. In other words, consider the implementation of btCollisionObject::isKinematicObject():
BTW: Kinematic objects can be active or inactive. Active kinematic objects will have their MotionState::getWorldTransform() called (if they have a Motionstate) once per simulation substep, but inactive kinematic objects will not. If you have a kinematic object that should never be deactivated then you would call setActivationState(DISABLE_DEACTIVATION) on it. I could imagine a few cases where kinematic objects could be allowed to go inactive (in particular, as an optimization for running large numbers of kinematic objects that are allowed to stop), however external logic would have to be properly instrumented to activate the objects when necessary: on key events or other logic/triggers.
Code: Select all
SIMD_FORCE_INLINE bool isKinematicObject() const
{
return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
}
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
How would i remove the collision flag? Are you saying its a like a toggle?
so if i turn a rigidbody to a kinematic like this ?
body0->setCollisionFlags(body0->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
i should then do this to toggle it back to a dynamics rigidbody?
body0->setCollisionFlags(body0->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
Please help
so if i turn a rigidbody to a kinematic like this ?
body0->setCollisionFlags(body0->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
i should then do this to toggle it back to a dynamics rigidbody?
body0->setCollisionFlags(body0->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
Please help
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
To clear just the CF_KINEMATIC_OBJECT flag you could do something like this:
Code: Select all
body0->setCollisionFlags(body0->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
I did that but it still isnt working is there something else i should do before or after i call that? I would think this would be really simple but its seems overly difficult!?
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Ah, I think your problem is that forceActivationState() doesn't reset the activation timer, so the object is getting deactivated almost immediately. Here is an excerpt from btCollisionObject.cpp:
So activate() will fail by default if the object is static or kinematic while forceActivationState() only sets m_activationState1. In conclusion you need to call activate() AFTER calling forceActivationState(). Alternatively, if you were to bump your object with another then the "dynamics world" would wake it up.
Code: Select all
void btCollisionObject::forceActivationState(int newState) const
{
m_activationState1 = newState;
}
void btCollisionObject::activate(bool forceActivation) const
{
if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
{
setActivationState(ACTIVE_TAG);
m_deactivationTime = btScalar(0.);
}
}
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Wow! this is really strange this is what im calling but the rigidbody still isnt moving this is weirdly complexm
body0->setCollisionFlags(body0->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
body0->forceActivationState(ACTIVE_TAG);
body0->activate();
body0->setCollisionFlags(body0->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
body0->forceActivationState(ACTIVE_TAG);
body0->activate();
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Did you perhaps clear the object's gravity? Or maybe you didn't set the gravity of the world?
Try giving it some velocity after activating it as a test.
Try giving it some velocity after activating it as a test.
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Another idea: when a btRigidBody is created it is set static by default (via the default btCollisionObject constructor from which btRigidBody derives). Perhaps you never cleared that flag and the object actually has both kinematic and static flags set? Try clearing both of flags whenever you try to set it dynamic.
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Yep still not working
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Should i ask erwin maybe?! This should be so simple!
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
My experience has been that when I am seeing an inexplicable bug it always sensible explanation when I figure out what the real problem is.
I've had one other idea: does your object happen to have zero mass?
I've had one other idea: does your object happen to have zero mass?
-
- Posts: 73
- Joined: Fri May 01, 2015 8:23 pm
Re: Is it possible to turn a Kinematic Rigidbody to a Dynami
Rigidbody has a mass of 1.0 this is really strange