A better way to "wake" physics objects?

Scripting questions, discussions, etc
2 posts Page 1 of 1
Posts: 12
Joined: Wed Jun 03, 2015 4:03 am
by benbeshara » Sat Oct 03, 2015 1:24 pm

At the moment in order to 'wake' physics objects so that the player character can interact with them I've added

Code: Select all

if(%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?

Posts: 374
Joined: Mon Feb 09, 2015 7:48 pm
by chriscalef » Sat Oct 03, 2015 6:14 pm
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:

Code: Select all

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.
2 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest