Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to enable gravity in PhysX

📅 2013-Dec-05 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ gravity, physx ⬩ 📚 Archive

Gravity is disabled by default in PhysX. To enable it, add a gravity vector to the scene descriptor:

physx::PxSceneDesc* sceneDesc;
// Assuming scene descriptor is created here
sceneDesc->gravity = physx::PxVec3(0.0f, -9.81f, 0.0f);

You can also set the gravity vector in the scene itself:

physx::PxScene* scene;
// Assuming scene is created here
scene->setGravity(physx::PxVec3(0.0f, -9.81f, 0.0f));

To avoid buggy behavior, it is better to enable gravity at the beginning.

Tried with: PhysX 3.2.4, Visual Studio 2010 and Windows 8 x64


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email