rraallvv
rraallvv

Reputation: 2943

Change btRigidBody's position/orientation on-the-fly in Bullet Physics

I know it breaks physics laws, but although there are often practical reasons to change instantaneously the position and orientation of a body in a game, most physic simulation libraries won't allow it, so Bullet Physics won't either.

So, I'd appreciate any suggestion or comment on this one.

By the way, teleportation comes to mind that requires those instant changes. Also a more exotic application could be inertia - for instance when tilting or rotating a portable device with accelerometer, so that objects would appear to be static in relation to the user. Augmented reality shouldn't sound cheesy.

Upvotes: 5

Views: 3408

Answers (1)

Jeremy Sandell
Jeremy Sandell

Reputation: 435

Assuming that I understand your question correctly, I'd recommend checking out BulletDynamics/Character/btCharacterControllerInterface.h and/or BulletDynamics/Dynamics/btActionInterface.h. Oftentimes one wants to "bend the rules" when implementing character movement - to implement teleporting, for example, one could use the void warp(const btVector3& origin) method from btCharacterControllerInterface.

Personally, I've had the best luck inheriting directly from btActionInterface, storing a pointer to a btGhostObject that I can update and implementing my logic from there, but YMMV.

Note: If you're just wanting to change the position and orientation, you should be able to call the void setWorldTransform(const btTransform& worldTrans) method for btRigidBody.

Upvotes: 2

Related Questions