skylicht-engine icon indicating copy to clipboard operation
skylicht-engine copied to clipboard

how to use Physics subsystem in Skylicht

Open bendico1 opened this issue 6 months ago • 0 comments

Hi, I 'm experimenting with the Physics subsystem: I loaded two game objects in .dae format, a box scaled along x and y axes to resemble a ground plane and a sphere. My idea is that the sphere, located a little bit in the air, falling down towards the floor at runtime. I'm using Linux Os and Code::Blocks as IDE. But the simulation doesn't run, there is a segmentation fault.

This is the workflow I used for this purpose:

//create an instance of the Physics subsystem in MyGame.h Physics::CPhysicsEngine* myPhyx = Physics::CPhysicsEngine::getInstance();

Then in MyGame.cpp:

// Physics initialization myPhyx->initPhysics();

//Physics stuff for plane plane->addComponent<Physics::CStaticPlaneCollider>(); Physics::CRigidbody* planeRB = plane->addComponent<Physics::CRigidbody>(); planeRB->setDynamic(false); planeRB->initRigidbody(); planeRB->setPosition(core::vector3df(0, -1, 0)); planeRB->syncTransform();

//Physics stuff for sphere
sphere->addComponent<Physics::CSphereCollider>(); Physics::CRigidbody* sphereRB = sphere->addComponent<Physics::CRigidbody>(); sphereRB->setDynamic(true); sphereRB->initRigidbody(); sphereRB->setPosition(core::vector3df(0, 4, 0)); sphereRB->syncTransform();

// update application in Update() Method float timestepSec = getTimeStep() / 1000.0f; myPhyx->updatePhysics(timestepSec); m_scene->update();

What's wrong? Which is the right implementation? Thanks for you kindly support.

bendico1 avatar Aug 18 '24 09:08 bendico1