[SOLVED] How to set rigid body of the node for collision(node is created by noderef)


photo

Recommended Posts

I am trying to add collision process for nodes.I already created contactcallback for intersection and it works like charm when i implement it directly to editor with calling by function in c++.So it directly detect intersection and collision wit contact callback function.

I would like to explain it with code;

It works correctly with this way

Unigine::NodePtr mObject1;
Unigine::NodePtr mObject1parent;

mObject1parent = Util::Search::getNodeRecursive("Objectparent", mReference->getNode());
mObject1 = Util::Search::getNodeRecursive("mObject1",mObject1parent); //I already added rigid body for object in unigine editor.

mObject1->getObjectBodyRigid()->getBody()->addContactCallback(Unigine::MakeCallback(this,contact_callback));//contact callback function detects intersections for collision


But I would like to remove Object1 from editor and add it dynamically with code.

Unigine::NodePtr mObject1;
Unigine::NodePtr mObject1parent;

mObject1parent = Util::Search::getNodeRecursive("Objectparent", mReference->getNode());
mObject1 = Util::Search::getNodeRecursive("mObject1",mObject1parent); //I disabled object1 from editor(something like removeving from editor)

//Then i added and created this object dynamically with below code:

Unigine::NodeReferencePtr tObject1 = Unigine::NodeReference::create("External/Entities/Object1.node");//this nodereference has node with rigid body inside 
tObject1->release();
Unigine::Editor::get()->addNode(tObject1->getNode(),1);
mObject1= tObject1->getNode();
mObject1->setWorldPosition(mObject1parent->getWorldPosition());
mObject1->setWorldRotation(mObject1parent->getWorldRotation());

//But unfortunately it does not get this Object1 node for collision, so below command gets trouble if we call rigid body of this node
//Basically it acts like this node is not exists.But i can set its position and direction and even i can move it in any axis.
 mObject1->getObjectBodyRigid()->getBody()->addContactCallback(Unigine::MakeCallback(this,contact_callback));

Any help will be appreciated.

Edited by burakdogancay
Link to post

1) a bit of optimization - don't decompose and compose the transformation matrix (if you don’t need it). This can lead to strange effects

mObject1->setWorldPosition(mObject1parent->getWorldPosition());
mObject1->setWorldRotation(mObject1parent->getWorldRotation());

to 

mObject1->setWorldTransform(mObject1parent->getWorldTransform());

such code suggests that you have scale changes?? Physics does not work with scaling objects!

 

2) 

48 minutes ago, burakdogancay said:

But i can set its position and direction and even i can move it in any axis.

how exactly? which node are you moving and how exactly?

3)

49 minutes ago, burakdogancay said:

mObject1 = Util::Search::getNodeRecursive("mObject1",mObject1parent); //I disabled object1 from editor(something like removeving from editor)

Disabled nodes are not deleted from the world.

 

4) According to the current code snippet, I can’t understand where exactly the error is. Сan you explain in more detail what exactly you want to do? Maybe some screenshots/videos?

Link to post

So i removed this below code and node from editor now.(Unfortunately i can not share any video for this project cause of policy)

mObject1parent = Util::Search::getNodeRecursive("Objectparent", mReference->getNode());
mObject1 = Util::Search::getNodeRecursive("mObject1",mObject1parent); //I already added rigid body for object in unigine editor.

İ used below code directly.

Unigine::NodePtr mObject1;
Unigine::NodePtr mObject1parent;


//Then i added and created this object dynamically with below code:

Unigine::NodeReferencePtr tObject1 = Unigine::NodeReference::create("External/Entities/Object1.node");//this nodereference has node with rigid body inside 
tObject1->release();
Unigine::Editor::get()->addNode(tObject1->getNode(),1);
mObject1= tObject1->getNode();
mObject1->setWorldPosition(mObject1parent->getWorldPosition());
mObject1->setWorldRotation(mObject1parent->getWorldRotation());

//But unfortunately it does not get this Object1 node for collision, so below command gets trouble if we call rigid body of this node
//Basically it acts like this node is not exists.But i can set its position and direction and even i can move it in any axis.
 mObject1->getObjectBodyRigid()->getBody()->addContactCallback(Unigine::MakeCallback(this,contact_callback));

So my problem is  , i can not reach the node but i can set its position and see the movement of the object according to its orientation.When i add contactcallback for this object it acts like it doesn't exist.Even i can not get its name by mObject1->getnode()->getname(), it return empty name for this object.

Link to post

try to change

Unigine::NodeReferencePtr tObject1 = Unigine::NodeReference::create("External/Entities/Object1.node");
tObject1->release();
Unigine::Editor::get()->addNode(tObject1->getNode(),1);
mObject1= tObject1->getReference(); // get Content node from noderef 
mObject1->setWorldPosition(mObject1parent->getWorldPosition());


can you show the nodereference structure from the editor?

111111.png

Link to post

Thank you so much problem is solved with " mObject1= tObject1->getReference(); "

I wish you a good day.

Link to post
  • morbid changed the title to [SOLVED] How to set rigid body of the node for collision(node is created by noderef)