Hi,
I tried it with Physics3DRigidBodyDes::originalTransform.translate, but it doesn’t seem to have any effect. No matter what translation I use, I always end up with the rigidbody centered in the middle of the sprite. How can it move the rigid body to another position relative to the sprite?
Here’s the code in charge:
cocos2d::PhysicsSprite3D* SpaceScene::createShip( const cocos2d::Vec3 &pos) {
char* model = "models/orc.c3b";
// just to get OBB
auto sprite = Sprite3D::create(model);
cocos2d::OBB _obb(sprite->getAABB());
Physics3DRigidBodyDes rbDes;
// next line has no effect at all
// no matter where I want to translate
rbDes.originalTransform.translate(Vec3(-100.0f, 0.0f, 0.0f));
rbDes.mass = 5.0f;
rbDes.shape = Physics3DShape::createBox(_obb._extents);
auto ship = PhysicsSprite3D::create(model, &rbDes);
auto rigidBody = static_cast<Physics3DRigidBody*>(ship->getPhysicsObj());
rigidBody->setLinearFactor(Vec3::ONE);
rigidBody->setLinearVelocity(Vec3::ZERO);
rigidBody->setAngularVelocity(Vec3::ZERO);
rigidBody->setCcdMotionThreshold(0.05f);
rigidBody->setCcdSweptSphereRadius(0.4f);
rigidBody->setDamping(0.9f, 0.9f);
ship->setPosition3D(pos );
ship->syncNodeToPhysics();
ship->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
ship->setCameraMask((unsigned short)CameraFlag::USER1);
return ship;
}
No matter what arguments I give to rbDes.originalTransform.translate, the output is always the same:
From my understandig of the code, the green box should be translated 100.0 on the x side, but nothing happens.
I have no clue what I’m doing wrong and would gladly appreciate any help on this.
Flo