Jump to content

Apply physics (gravity, collision, etc) to dynamically created ObjectMeshDynamic


photo

Recommended Posts

Posted

I am creating a simple project that allows the user to spawn an object when the mouse is clicked. I would like for this object to respond appropriately to physics forces -- falling due to gravity, colliding with terrain and other objects, etc. At this point, I have an ObjectMeshDynamic being created, a mesh loaded, and a material and property applied. The object appears in the scene as expected, but it does not respond to physics. Instead it just hovers in place in the position it was created.

 

I am implementing this in C++ rather than UnigineScript.

ObjectMeshDynamicPtr object = ObjectMeshDynamic::create(1);
object->loadMesh(meshFilename);
object->setWorldTransform(transform);


for(int i = 0; i < object->getNumSurfaces(); i++) {
  object->setMaterial("mesh_base",i);
  object->setProperty("surface_base",i);
}

I suspect that I need to use a class other than ObjectMeshDynamic in order to make this work, perhaps something akin to UnigineScript's Body class. Please advise. Thanks in advance.

Posted

Hello Adam (what a good name!),

 

That's because you created a node without physical body assigned to it. So if you create one you'll get your physics applied to the node. But the bad news is we don't have such API on the C++ side, so it's only possible in the script.

 

On the other hand, you can pass node created from C++ to the script function and assign a body inside that function.

×
×
  • Create New...