# Defining Node adding Spatial with Physic have weird results

What is the best way to handle this.

If a create a Node and attached 2 Spatial to the node. I give the Node positional information and when I attach 1st children with 0,0,0 translation (no offset) and then 2nd one with (2,0,0) giving (offset of 2 x). and attach them to rootNode.

Everything works great.

Now 2 version.

If I do the same but this time I want to do the same thing but I need to give the 2 children physics and add them to physic space.

How do you do this. You can add the physics to the children and attach them to the Node, Because the physics appear to â€śONLYâ€ť use the spatial translation and not use the main Node.

So what is the way to place certain spatial into a node so that you can handle the children correctly when they have physics?

I hope I"m clear.

Example 1: I try to add phsyics to Node and placement is correct but Spatial donâ€™t have physics.

``````    private Node addGrass(int model, int pos)
{
Node grassNode = new Node("grass");
grassNode.setLocalTranslation(0, 0, pos * terrianWidth);

Material mat = new Material(this.getApplication().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
Texture cube1Tex;
if (model == 0)
else
mat.setTexture("DiffuseMap", cube1Tex);
spatial.setMaterial(mat);
spatial.setName("grass");
//        spatial.setLocalTranslation(0, 0, pos * terrianWidth);

RigidBodyControl rigidControl = new RigidBodyControl(0);

grassNode.attachChild(spatial);
return grassNode;
}
``````

Example 2: I add physics to the Spatial and attach the Spatial to the Node. Physics are correct but placement is at 0,0,0 because Spatial has not translation and physics appear to work off the spatial and doesnâ€™t take Node in.

``````    private Node addGrass(int model, int pos)
{
Node grassNode = new Node("grass");
grassNode.setLocalTranslation(0, 0, pos * terrianWidth);

Material mat = new Material(this.getApplication().getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
Texture cube1Tex;
if (model == 0)
else
mat.setTexture("DiffuseMap", cube1Tex);
spatial.setMaterial(mat);
spatial.setName("grass");
//        spatial.setLocalTranslation(0, 0, pos * terrianWidth);

RigidBodyControl rigidControl = new RigidBodyControl(0);

grassNode.attachChild(spatial);
return grassNode;
}
``````

So can you add physics to items that are under a Node because I need to delete a entire group at once and it would be easier to just find the parent and delete that instead of finding all the physics and deleting them one by one.

Thanks.

Should the objects move independently or are they effectively treated as one object?

If the latter then a compound collision shape + rigid body on the node might work better. JME even has utilities to make such things as I recall.

If the former then you are going to have a bad time. Itâ€™s not clear how they should behave independently as the node moves and the conflation of game object and visual object that JME makes so easy will be a constant struggle.

Thanks. Nothing moves per say. Only the camera. The camera moves and new Pieces in chunks are placed and as old pieces leave the screen I remove them.

Doing a compound collision shape on the node would work out for some.
But I have chunks where it is a combo of non-physic objects and physic objects. What is the best way to handle them. Basically saying putting them in a Node doesnâ€™t work.

You can create the compound collision shape yourself, tooâ€¦ and thus ignore or include whatever you want. I only mentioned the utility for convenience but all itâ€™s doing is a recursive scene graph traversal.

Another question, The wiki pages says if you remove a Node it removes all its children and if there are physic controls they will be removed from physic space.

I donâ€™t see this. I have to manually loop through all the children and get their controls and see if it is a physic control and then manually call remove from physic space for that spatial.

Is it suppose to remove them for you or is the wiki pages wrong.

Forgot to mention, Iâ€™m using Minie

1 Like

Pretty sure that canâ€™t be true. But I admit Iâ€™m not intimately familiar with the JME bullet integration. Even when Iâ€™ve used bullet, it was just for my game objects and not directly attached to spatials.

2 Likes

Paulâ€™s right, and hereâ€™s why:

• Detaching a node from the scene detaches all its children from the scene.
• Disabling a physics control (or removing it from a spatial) should remove its collision objects (if any) from the physics space (if any).

However, detaching a spatial from the scene doesnâ€™t disable or remove its controls. To maintain a clean physics space, disable/removal of physics controls should be done explicitly.

Edit: I realize the above is potentially confusing, since â€śremoveâ€ť refers to at least 2 distinct operations and â€śphysics controlsâ€ť are often conflated with â€ścollision objectsâ€ť. I encourage you to keep asking questions until itâ€™s all clear.