Physics 3d World simulation

In my 3d game I have created physics 3d world.But its not simulating and its working very slow.when i call
scene->getPhysics3DWorld()->stepSimulate(dt*100);
the frame rate is 0.2/7.0
if()
scene->getPhysics3DWorld()->stepSimulate(dt/100);
frame rate is 32/0.030
But the bodies are moving very slowly and they are not functioning as desired giving abrupt results.
Thanx in advance
:smile:

Try with fixed timestep for example 1/60.

I am doing the same.But no new result.Same as previous .

Looking at the source i don’t think you are supposed to manually call stepSimulate. If you are using Scene with createWithPhysics() it will automatically create World for you and step it. You just need to set time interval.

Check this link

http://www.cocos2d-x.org/programmersguide/12/index.html

1 Like

do you know why my obj. doesnt fall down ?

auto scene = Scene::createWithPhysics();
scene->getPhysics3DWorld()->setGravity(Vec3(0,-10,0));

auto layer = HelloWorld::create();
layer->SetPhysics3DWOrld(scene->getPhysics3DWorld());
scene->addChild(layer);

First

Physics3DRigidBodyDes rbDesx;
rbDesx.mass = 0.0f;
rbDesx.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
robo = PhysicsSprite3D::create("tortoise.c3b", &rbDesx);
robo->setTexture("tortoise.png");
robo->setScale(3.0f);
robo->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
robo->setPositionZ(0);
robo->setPositionY(0);
robo->setPositionX(0);
robo->setGlobalZOrder(-1);
robo->syncNodeToPhysics();
robo->syncNodeToPhysics();
robo->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
robo->setCameraMask((unsigned short)CameraFlag::USER2);
addChild(robo);

Second

Physics3DRigidBodyDes rbDesxx;
rbDesxx.mass = 0.0f;
rbDesxx.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
robox = PhysicsSprite3D::create("tortoise.c3b", &rbDesxx);
robox->setTexture("tortoise.png");
robox->setScale(0.01f);
robox->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
robox->setPositionZ(0);
robox->setPositionY(800);
robox->setPositionX(0);
robox->setGlobalZOrder(-1);
robox->syncNodeToPhysics();
robox->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
robox->setCameraMask((unsigned short)CameraFlag::USER2);
addChild(robox);

i think there should be
this->scene()->setPhysics3DDebugCamera(camera); // but idoesnt work correctly

Director::getInstance()->getRunningScene()->setPhysics3DDebugCamera(camera); // the same

Well we can simulate the world manually either by making setAutoStep(false) or not.
Both the ways guarantee the world simulation.I have used stepSimulate() in my project and its working fine in case it is only a default structure.
But when I am using it with other structure it is not working.

I have checked it and found the same.But I found a solution you can check on it…
Physics3DRigidBodyDes rbDesx;
rbDesx.mass = 1.0f;
rbDesx.shape = Physics3DShape::createBox(Vec3(5, 1.0f, 5));
auto rbd = Physics3DRigidBody::create(&rbDesx);
auto rbc = Physics3DComponent::create(rbd);
auto robo = Sprite3D::create(“box.c3t”);
robo->setTexture(“tortoise.png”);
robo->addComponent(rbc);
robo->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(robo);
robo->setScaleX(5);
robo->setScaleY(1);
robo->setScaleZ(5);
robo->setPosition3D(Vec3(Director::getInstance()->getVisibleSize().width / 2 + Director::getInstance()->getVisibleOrigin().x, Director::getInstance()->getVisibleSize().height / 2 + Director::getInstance()->getVisibleOrigin().y, 0));
robo->setPositionZ(0);
robo->setPositionY(0);
robo->setPositionX(0);
robo->setGlobalZOrder(-1);
robo->setCameraMask((unsigned short)CameraFlag::USER1);
rbc->syncPhysicsToNode();

yup now it’s working correct. the problem was a mass i think
rewrite code:

Physics3DRigidBodyDes rbDesxs;
rbDesxs.mass = 1.0f;
rbDesxs.shape = Physics3DShape::createBox(Vec3(5, 1.0f, 5));
auto rbds = Physics3DRigidBody::create(&rbDesxs);
auto rbcs = Physics3DComponent::create(rbds);
robox = Sprite3D::create(“tortoise.c3b”);
robox->setTexture(“tortoise.png”);
robox->setScale(0.01f);
robox->setPosition3D(Vec3(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y, 0));
robox->setPositionZ(0);
robox->setPositionY(800);
robox->setPositionX(0);
robox->setGlobalZOrder(-1);
robox->addComponent(rbcs);
rbcs->syncNodeToPhysics();
rbcs->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
robox->setCameraMask((unsigned short)CameraFlag::USER2);
this->addChild(robox);

Hi @equeliper

I tried your last posted code, but I do not see anything on my screen, it’s blank.

Is there anything that need to be added ?
or could you please share some sample codes… !!

Thanks in advance. :smile: