sarkozy
December 23, 2009, 3:43pm
1
hi,
i made the colision teste in my game, but is identified colision when the models are still distant…
my code:
public boolean colision (Node Modelo)
{
CollisionTreeManager.getInstance().setTreeType(CollisionTree.Type.AABB);
CollisionResults results = new TriangleCollisionResults();
for (int i=0;i<node.getChildren().size();i++)
{
if ( ! Modelo.getName().equalsIgnoreCase(node.getChild(i).getName()) )
{
results.clear();
Modelo.findCollisions(node.getChild(i), results);
if (results.getNumber() > 0);
return true;
}
}
return false;
}
whats the problem?
Is this part of code doing what you want ?
if (results.getNumber() > 0);
return true;
sarkozy
December 23, 2009, 7:45pm
3
No, this “;” I accidentally put in the code …
There is no syntax error in my code … my problem is that my function accuses collision between objects just before the objects collide … I put a picture of what is happening:
This message box appears when my function returns true …
normen
December 23, 2009, 9:08pm
4
The collision is based on the BoundingVolume of your spatial. If it is a sphere, it is probably bigger than the box itself…
sarkozy
December 23, 2009, 9:54pm
5
I changed to BoundingBox and still the same error …
s = new Box("s",new Vector3f(0,0,0), 5,5,5);
s.setLocalTranslation(0,0,0);
BoundingVolume b = new BoundingBox();
s.setModelBound( b);
s.updateWorldBound();
s.updateModelBound();
s.updateRenderState();
s2 = new Box("s2",new Vector3f(0,0,0), 5,5,5);
s2.setLocalTranslation(-20,0,0);
s2.setModelBound(b);
s2.updateWorldBound();
s2.updateModelBound();
s2.updateRenderState();
I have to give volume for boudingBox? What do I do?
ttrocha
December 23, 2009, 10:41pm
6
Are you using SimpleGame? If yes you can show the BoundingVolumes by pressing B.
I think your problem is that getNumber() will not help you here. As far as I know you have to check if there are really triangle-hits
add something like this before returning true:
for (int i=0;i<results.getNumber();i++)
{
if (results.getCollisionData(i).getTargetTris().size()>0)
return true;
}
Maybe you should use a different approach:
if (b1.hasCollision(b2, true)) return true;
the "true" in the hasCollision-method means trianglecollision yes/no
good luck...collision-detection is able to make you crazy (I'm having some issues at the moment as well)
sarkozy
December 24, 2009, 12:56am
7
Perfect!
I used the first way you said and it worked perfectly!
thank you very much!