Jump to content

Switch from physical body to "static" collision


photo

Recommended Posts

Posted

I need realize some logic, when I can enable/disable physical body of object, so in one time it be physical, and in another - this is only static mesh with "static" collisions.

I use NodeReference node in game, get it physical body of it inner Node, and use Body::setEnabled(false); - but in this case node has no collision with any object or player, but if I remove Body from NodeReference in Editor mode, save it and load in game, then I will have "static" collision.

Question: how can I switch from body collision to "static" mesh collision and back for my NodeReference node?

Posted

Set zero mass for all shapes.

Sorry, not understand, is next right?

NodeReference cube = new NodeReference("source/nodes/cube_blue.node");
cube.setPosition(pos);

Object innerObject = node_cast(cube.getNode());
BodyRigid body = innerObject.getBodyRigid();

for (int i = 0; i < body.getNumShapes(); i++)
{
Shape shape = body.getShape(0);
shape.setMass(0.0f);
}

body.setEnabled(false);

Cause it don't work :(

Posted

Cause it don't work :(

 

Have you tried it with body.setEnabled(true) ?

Posted

Have you tried it with body.setEnabled(true) ?

With body.setEnabled(true) it works. But I need disable Body, cause I need scale my object... I use unit scale, when I need to interact with physical object, and then in some moment I need to disable physical behavior, set different scale and leave object, but I need that another objects and player will collide with it. Then in some moment I need take this object, set unit scale and enable physical behavior.

Posted

With body.setEnabled(true) it works. But I need disable Body, cause I need scale my object... I use unit scale, when I need to interact with physical object, and then in some moment I need to disable physical behavior, set different scale and leave object, but I need that another objects and player will collide with it. Then in some moment I need take this object, set unit scale and enable physical behavior.

 

Does sound a little bit complicated. As far as I know scaling for body shapes is not really supported. Anyway alternetivly you could provide 2 shapes (one unscaled and one scaled) and used appropriate Shape::setEnabled( true/false) calls based on game state.

Posted

I don't scale body shapes. I disable body, and scale object (mesh), when I enable body, it already the same, unit scale.

We can leave scale now, and it is all the same: when I disable physical body object not react like simple mesh with collision and intersection.

×
×
  • Create New...