Locking A Door (uses limited hinge constraints)

Locking A Door (uses limited hinge constraints)

I'm trying to implement a door, I have the hinge constraints working fine, but the character controller can push the door. How would I implement a lock so that the door will not move until it is unlocked?

3 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.
Best Reply

Hey edcampion!
One way to achieve what you are looking for is changing the door's rigid body from hkpMotion::FIXED to hkpMotion::DYNAMIC once it is unlocked.A demo that illustrates this is:

Physics > Api > Dynamics > RigidBodies > MotionTypeChange
It also mentions one caveat when using this technique: You can create the constraints at startup, but you can't set the rigid body motion type to be FIXED at creation. This is because Havok stores FIXED and DYNAMIC types slightly differently. The way to deal with this is to define the door as DYNAMIC at creation but then after you have called the constructor, call the setMotionType() function. For example, this would work:

//set all the hkpRigidBodyCinfo fields here, then set the motion type as DYNAMIC

info.m_motionType = hkpMotion::MOTION_DYNAMIC;

doorRigidBody = new hkpRigidBody( info ); //RB is created as DYNAMIC body

doorRigidBody->setMotionType(hkpMotion::MOTION_FIXED); //now it's okay to set it back to FIXED
The reason for this is explained in "Havok_Physics_Animation_2011-3-0_Pc_Xs_User_Guide" under:Havok Physics > Simulating a Physics World > Populating a World > Changing the Motion State
Another way that could work would be to define the door as DYNAMIC, but then initially set its mass to 0 (which makes it infinitely massive so it won't be affected by any forces or other objects) and then change its mass to something realistic during the unlock event. Having tested the first solution I'd recommend you try that first, but this way is worth a try.
Hope that helps!

Developer Support Engineer

Thanks Josh. First solution works great.

Kommentar hinterlassen

Bitte anmelden, um einen Kommentar hinzuzufügen. Sie sind noch nicht Mitglied? Jetzt teilnehmen