Detecting overlaps - collideWith()

Hello. I’m experimenting with using collideWith() to detect overlaps between robots. I do this by creating BoundingVolumes of the Nodes the robots are attached to:

[java]CollisionResults results = new CollisionResults();

BoundingVolume bv = robotANode.getWorldBound();

robotBNode.collideWith(bv, results);[/java]

The way I understand it is that this will create BoundingVolumes of all children of the robotNodes and then check for collisions. Without having tested with the actual robot models yet, I suspect that this might require a lot of CPU because the robot models are pretty detailed and contains a lot of triangles/vertices.

It is not actually necessary for me to check for collisions this accurately. I could just as well create bounding boxes around each moving part of the robot (leg, arm, head, etc), and then only have to check a few BoundingVolumes when detecting collisions. Is it possible to create BoundingBoxes like this and attach them to the nodes of the robot, so that I can to a collision checks similar to the above code (without all the detailed geometries being compared)?

All Geometry has BoundingVolumes already for culling etc. which is also used for the overlap checks. The needed geometry info is created once when the first collideWith() is called. You could use GhostControls and static RigidBodyControls to do collision checks too.

Thank you for the quick response :). It sounds like collideWith() should be pretty efficient then when it comes to CPU useage.

Does GhostControl have any advantage over collideWith()? All movements of the robots will be done with setLocalTranslation() and setLocalRotation(). I looked at using GhostControl yesterday:

New attempt at the link: :wink:

I’m having trouble when checking for overlap between tilted objects. The bounding box doesn’t seem to tilt along with the geometry. This causes an overlap to be detected when there is none.

The code I’m using:

[java]import com.jme3.scene.Node;



import com.jme3.bounding.BoundingBox;

import com.jme3.bounding.BoundingVolume;

import com.jme3.collision.CollisionResults;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Spatial;

import com.jme3.scene.shape.Box;

public class TestOverlap extends SimpleApplication {

protected Node robotANode;

protected Geometry geomA1;

protected Node robotBNode;

protected Geometry geomB1;

public TestOverlap() {



public static void main(String[] args) {

Application app = new TestOverlap();




public void simpleInitApp() {

robotANode = new Node();


Box boxA = new Box(new Vector3f(0, 0, 0), 2, 0.5f, 0.5f);

geomA1 = new Geometry(“Box”, boxA);

setMaterial(geomA1, ColorRGBA.Blue, “Common/MatDefs/Misc/SolidColor.j3md”);

geomA1.setModelBound(new BoundingBox(new Vector3f(0, 0, 0), 2, 0.5f, 0.5f));



robotBNode = new Node();


Box boxB = new Box(new Vector3f(0, 0, 0), 2, 0.5f, 0.5f);

geomB1 = new Geometry(“Box”, boxB);

setMaterial(geomB1, ColorRGBA.Green, “Common/MatDefs/Misc/SolidColor.j3md”);

geomB1.setModelBound(new BoundingBox(new Vector3f(0, 0, 0), 2, 0.5f, 0.5f));





private void setMaterial(Geometry geometry, ColorRGBA color, String type) {

Material material = new Material(assetManager, type);

material.setColor(“Color”, color);




public void simpleUpdate(float tpf) {

float curTime = timer.getTimeInSeconds();

robotANode.setLocalTranslation((float) Math.cos((double) curTime), 0, 0);

CollisionResults results = new CollisionResults();

BoundingVolume bv = geomB1.getWorldBound();

geomA1.collideWith(bv, results);

if (results.size() > 0) {



else {





How can I get the bounding volume to rotate along with the geometry.

@12monkeys said: How can I get the bounding volume to rotate along with the geometry.

there is bounding sphere and axis aligned bounding box and they does not rotate because it is easier to implement and faster for collision detection