# Non physical Collisions, mathematical Collisions

Hi there,

why am I getting an “com.jme3.collision.UnsupportedCollisionException”. In the Tutorial (Link) it is written that the “collideWith()-method” is executable on Nodes. My code executes the method on two nodes, but the error occurs. Can you perhaps tell me why? Here is my code, by pressing “k” the AnalogListener is turned on and the error occurs.

[java]

import com.jme3.app.SimpleApplication;

import com.jme3.bounding.BoundingBox;

import com.jme3.collision.CollisionResults;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Ray;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Node;

import com.jme3.scene.shape.Box;

public class MySimpleApplication4 extends SimpleApplication {

//box1 field

Box box1;

BoundingBox b_box1;

Geometry g_box1;

Material m_box1;

Node n_box1;

//box2 field

Box box2;

BoundingBox b_box2;

Geometry g_box2;

Material m_box2;

Node n_box2;

//analogListener field

AnalogListener analogListener;

CollisionResults collisionResults;

@Override

public void simpleInitApp() {

//cam settings

flyCam.setMoveSpeed(50);

flyCam.setRotationSpeed(3);

cam.setLocation(new Vector3f(2, 0, 10));

cam.lookAt(new Vector3f(3, 0, -10), Vector3f.UNIT_Y);

//init box1 field

box1 = new Box(Vector3f.ZERO, 2f, 0.5f, 0.5f);

b_box1 = new BoundingBox(Vector3f.ZERO, 0.5f, 0.5f, 0.5f);

box1.setBound(b_box1);

g_box1 = new Geometry(“box1”, box1);

m_box1.setColor(“Color”, ColorRGBA.Yellow);

g_box1.setMaterial(m_box1);

n_box1 = new Node();

n_box1.attachChild(g_box1);

//init box2 field

box2 = new Box(Vector3f.ZERO, 0.2f, 2f, 3f);

b_box2 = new BoundingBox(Vector3f.ZERO, 0.5f, 0.5f, 0.5f);

box2.setBound(b_box2);

g_box2 = new Geometry(“box2”, box2);

m_box2.setColor(“Color”, ColorRGBA.Pink);

g_box2.setMaterial(m_box2);

n_box2 = new Node();

n_box2.attachChild(g_box2);

n_box2.setLocalTranslation(new Vector3f(3,0,0));

//init listener field, moves box1

analogListener = new AnalogListener() {

@Override

public void onAnalog(String name, float value, float tpf) {

if (name.equals(“move”)) {

collisionResults = new CollisionResults();

int num_of_collisions = collisionResults.size();

n_box1.collideWith(n_box2, collisionResults);

if (num_of_collisions>0) {

System.out.println(“dont move n_box1 further”);

}else{

System.out.println(“move n_box1 further”);

Vector3f pos_n_box1 = n_box1.getLocalTranslation();

float pos_x = pos_n_box1.getX();

float pos_y = pos_n_box1.getY();

float pos_z = pos_n_box1.getZ();

n_box1.setLocalTranslation(pos_x + tpf, pos_y, pos_z);

}

}

}

};

rootNode.attachChild(n_box1);

rootNode.attachChild(n_box2);

}

public static void main(String[] args) {

MySimpleApplication4 a = new MySimpleApplication4();

a.start();

}

}

[/java]

What should happen is: the box should be moved until “collisionResults” is greater than 0.

What have i done wrong ?

First of all you get the result size before you do the collision check. Then you can only collide geometry vs bounding volumes or rays, e.g. rootNode.collideWith(boundingBox);

@normen said:
First of all you get the result size before you do the collision check.

Ok getting the size before is stupid. im going to change that.
@normen said:
Then you can only collide geometry vs bounding volumes or rays, e.g. rootNode.collideWith(boundingBox);

This is Strange the Tutorial link says that.
The collision parties can be Geometries, Nodes with Geometries attached (including the rootNode), Planes, Quads, Lines, or Rays.

And you tell me something different.

EDIT:
Even if i change my code to node_box1.collideWith(boundingBox_box2); it always tells me "dont move n_box1 further", so collisionResults is despite the fact that they dont intersect each other always >0. Super-Strange. Why?
@kaaltek said:
This is Strange the Tutorial link says that.
And you tell me something different.

You're interpreting your beliefs into one piece of text. Ofc you can (and will) choose to believe whatever you want, I guess you will be quicker by believing me.

Updated the tutorial with the following “An important restriction is that you can only collide geometry vs bounding volumes or rays.”

@normen said:
You're interpreting your beliefs into one piece of text. Ofc you can (and will) choose to believe whatever you want, I guess you will be quicker by believing me.

I dont think that it is interpreting beliefs into text here, it is about understanding what is written (and changed now by jmassing). But forget that, i changed the code and always getting a num_off_collisions > 0 ? but the objects do not intersect.

EDIT:
Found the error. Thank you both. Heres the working code:

[java]
import com.jme3.app.SimpleApplication;
import com.jme3.bounding.BoundingBox;
import com.jme3.collision.CollisionResults;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;

public class MySimpleApplication4 extends SimpleApplication {

//box1 field
Box box1;
BoundingBox b_box1;
Geometry g_box1;
Material m_box1;
Node n_box1;

//box2 field
Box box2;
BoundingBox b_box2;
Geometry g_box2;
Material m_box2;
Node n_box2;

//analogListener field
AnalogListener analogListener;

@Override
public void simpleInitApp() {
//cam settings
flyCam.setMoveSpeed(50);
flyCam.setRotationSpeed(3);
cam.setLocation(new Vector3f(2, 0, 10));
cam.lookAt(new Vector3f(3, 0, -10), Vector3f.UNIT_Y);

//init box1 field
box1 = new Box(Vector3f.ZERO, 2f, 0.5f, 0.5f);
b_box1 = new BoundingBox(Vector3f.ZERO, 2f, 0.5f, 0.5f);
box1.setBound(b_box1);
g_box1 = new Geometry("box1", box1);
m_box1.setColor("Color", ColorRGBA.Yellow);
g_box1.setMaterial(m_box1);
n_box1 = new Node();
n_box1.attachChild(g_box1);

//init box2 field
box2 = new Box(Vector3f.ZERO, 0.2f, 2f, 3f);
g_box2 = new Geometry("box2", box2);
m_box2.setColor("Color", ColorRGBA.Pink);
g_box2.setMaterial(m_box2);
n_box2 = new Node();
n_box2.attachChild(g_box2);
n_box2.setLocalTranslation(new Vector3f(3,0,0));
b_box2 = new BoundingBox(n_box2.getLocalTranslation(), 0.2f, 2f, 3f);
box2.setBound(b_box2);

//init listener field, moves box1
analogListener = new AnalogListener() {
@Override
public void onAnalog(String name, float value, float tpf) {
if (name.equals("move")) {
CollisionResults collisionResults = new CollisionResults();
n_box1.collideWith(b_box2, collisionResults);
int num_of_collisions = collisionResults.size();
if (num_of_collisions>0) {
System.out.println("dont move n_box1 further");
for (int i = 0; i < num_of_collisions; i++) {
Vector3f contact_point_i = collisionResults.getCollision(i).getContactPoint();
System.out.println("collision i="+i+"n"+
"collision i contact_point="+contact_point_i);
}
}else{
System.out.println("move n_box1 further");
Vector3f pos_n_box1 = n_box1.getLocalTranslation();
float pos_x = pos_n_box1.getX();
float pos_y = pos_n_box1.getY();
float pos_z = pos_n_box1.getZ();
n_box1.setLocalTranslation(pos_x + tpf, pos_y, pos_z);
}
}
}
};

rootNode.attachChild(n_box1);
rootNode.attachChild(n_box2);
}

public static void main(String[] args) {
MySimpleApplication4 a = new MySimpleApplication4();
a.start();
}
}
[/java]
@kaaltek said:
I dont think that it is interpreting beliefs into text here, it is about understanding what is written

If it was about that then my comment should have sufficed? You were talking about the discrepancy between what I said and what the text says in your opinion.
@normen said:
If it was about that then my comment should have sufficed? You were talking about the discrepancy between what I said and what the text says in your opinion.

A belief, as you put it, differs -in my humble opinion- from understanding, which is what I had about the text.
@kaaltek said:
A belief, as you put it, differs -in my humble opinion- from understanding, which is what I had about the text.

I thought you came to the forums to improve your understanding, my mistake.
@normen said:
I thought you came to the forums to improve your understanding, my mistake.

The sentence in the Link before the paragraph was edited:
"The collision parties can be Geometries, Nodes with Geometries attached (including the rootNode), Planes, Quads, Lines, or Rays."

From this sentence follows that NODE_X.collideWith(NODE_Y, results) is possible, which is obviously not. And you still argue it is my belief or something. Funny.
EDIT:
this is somehow becoming more off topic or private chat...
@kaaltek said:
The sentence in the Link before the paragraph was edited:
"The collision parties can be Geometries, Nodes with Geometries attached (including the rootNode), Planes, Quads, Lines, or Rays."

From this sentence follows that NODE_X.collideWith(NODE_Y, results) is possible, which is obviously not. And you still argue it is my belief or something. Funny.
EDIT:
this is somehow becoming more off topic or private chat...

Well you started it, the wiki is editable :) Just saying "you said this, the wiki said that" will only get you discussions as these I am afraid :P The sentence in the tutorial is still true when I make the restriction that the party supplied to the method parameter has to be a bounding volume. The sense you saw in it has in fact been your own belief solely. I am sure in other parts of the manual and in the javadoc its mentioned, not to mention the actual error message does mention the restriction.
@normen said:
Well you started it, the wiki is editable :) Just saying "you said this, the wiki said that" will only get you discussions as these I am afraid :P The sentence in the tutorial is still true when I make the restriction that the party supplied to the method parameter has to be a bounding volume. The sense you saw in it has in fact been your own belief solely. I am sure in other parts of the manual and in the javadoc its mentioned, not to mention the actual error message does mention the restriction.

In my oppinion the sentece was misleading.