set pos of RigidBodyCombiner node

Hi all,

I try using the following code:

[b]NodePath * rbcNP;
RigidBodyCombiner rbc("");

NodePath unit;

rbcNP = new NodePath(&_rbc);
rbcNP->reparent_to(rootNode);

unit = rbcNP->attach_new_node("");
rbc.collect();

otherNode.copy_to(unit);
unit.set_pos(LPoint3f(100,100,0));[/b]

And the “unit” is displayed at (0,0,0),
the set_pos doesn’t effect it…
When I print the: “unit.get_pos()” it’s give me the one I set (meaning (100,100,0)).

So why does it display the model at (0,0,0) and not at (100,100,0) as i asked…?

10X !

From the RigidBodyCombiner API page:

Your node does not have a transform on it, nor is it a ModelNode, at the time of collect(), so it does not get identified as a “moving” node.

To fix this, either replace:

unit = rbcNP->attach_new_node("");

with:

unit = rbcNP->attach_new_node(new ModelNode());

or move the call to unit.set_pos() to before the call to collect().

Note that, by the way, NodePath objects are intended to be created directly on the stack, not indirectly via the new operator. So you can do:

NodePath rbcNP(&_rbc);
rbcNP.reparent_to(rootNode);

But this is a minor detail.

David

First of all,
Thank you David, you are the best!

I try both of your suggestes and still the model is in (0,0,0)… :frowning:

What else can i do?

move the node a tiny bit away from 0,0,0 before you collect them. like 0.0000001 or so.

Thank you ThomasEgi for your repley,
But believe me I try all the combinations,
I try to collect before, after in the middle and so…
:slight_smile:

Ah, another problem may be the way you are declaring your RBC. Unlike NodePath, RigidBodyCombiner inherits from PandaNode, which inherits from ReferenceCount. All objects that inherit from ReferenceCount must be declared dynamically and stored in a PT() object.

So, you should replace:

RigidBodyCombiner rbc("");

with:

PT(RigidBodyCombiner) rbc = new RigidBodyCombiner("");

Also, I note that you reference a different object, _rbc. Make sure that you don’t have two different RigidBodyCombiner objects here that you’re getting confused with each other.

David

Thank’s again david,

I change the code as you say to PT, and as you say at your first command (the rbcNP is not a pointer any more…), but still the object is at (0,0,0) and won’t move that location ! :smiling_imp:

So I try to replace the model in the same code with the LineSegs object, and it’s work… !!

Can it be the model? some thing in my egg file?
or may be the code line:
otherNode.copy_to(unit);
is making the problem?

My code now is looking like this:

[b]NodePath rbcNP;
PT(RigidBodyCombiner)rbc = new RigidBodyCombiner("");

NodePath unit;

rbcNP = NodePath(rbc);
rbcNP.reparent_to(rootNode);

unit = rbcNP.attach_new_node(new ModelNode(""));
otherUnit.copy_to(unit);
unit.set_pos(100,100,0);

rbc->collect();[/b]

DONE ! :laughing:

I just remove the:

character {
{ 1 }

From my egg file, and the unit is no longer at (0,0,0).

Again thank you all for the help!