benbeshara Posted October 3, 2015 Share Posted October 3, 2015 Hi,At the moment in order to 'wake' physics objects so that the player character can interact with them I've addedif(%col.getClassName() $= "PhysicsShape"){ %col.applyImpulse("0, 0, 0", 2); }to the bottom of PlayerData::onCollision. I've tried exposing the setSleeping variable to script as an alternative means but had no luck with it.It's entirely possible that I'm completely misunderstanding how physicsShapes are supposed to work, but as far as I can tell during the simulation they sleep when their level of motion is reduced to a small enough level and can only be woken again by interactions from another physics object or by having applyImpulse() called.Is there a better way to wake physicsShapes? Or a way to set them not to sleep if, say, the player is in close proximity?Thanks Quote Link to comment Share on other sites More sharing options...
chriscalef Posted October 3, 2015 Share Posted October 3, 2015 The way I handled this is adding the following function to px3Body (it should probably get more generalized and moved up to physicsBody, so as to more easily implement the same thing in bullet, but I'm physx3 focused and it was faster to put it here: In px3Body.h: virtual void setDynamic( bool isDynamic ); In px3Body.cpp: void Px3Body::setDynamic( bool isDynam ) { bool isKinematic = mBodyFlags & BF_KINEMATIC; if (isDynam==isKinematic) { //ie we're switching states, we were kinematic and now we want to be dynamic, or vice versa. physx::PxRigidDynamic *kBody = static_cast<physx::PxRigidDynamic*>(mActor); if (isDynam) { kBody->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, false); mBodyFlags &= ~PhysicsBody::BF_KINEMATIC; } else { kBody->setRigidDynamicFlag(physx::PxRigidDynamicFlag::eKINEMATIC, true); mBodyFlags |= PhysicsBody::BF_KINEMATIC; } } } You can then call that like mPhysicsRep->setDynamic(true) from a PhysicsShape when you want a live object, and send it false to put it to sleep. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.