collideWith() giving too long results lists

Hi, I’m having troubles with some collisions. I’m trying to check if a player gets in an area so I made a “Box” with:

public class DangerArea extends Node {
    static float RADIUS = 5f;
    Spatial area;
    
    public DangerArea() {
        
        /*area = new Geometry("Visible box", new Cylinder(4, 3, RADIUS, 5f, true));
        area.rotate(90f*FastMath.DEG_TO_RAD, 30f*FastMath.DEG_TO_RAD, 0f);
        area.setLocalTranslation(new Vector3f(0f,0f,-(RADIUS-2)));*/
        area = box();
        this.attachChild(area);

        Material areaMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        Texture areaTex = assetManager.loadTexture( "Interface/Logo/Monkey.jpg");
        areaMat.setTexture("ColorMap", areaTex);
        areaMat.getAdditionalRenderState().setWireframe(true);
        areaMat.setColor("Color", ColorRGBA.Red);
        area.setMaterial(areaMat);
    }
    
    private Geometry box(){
        Geometry shape = new Geometry("Visible box", new Box(Vector3f.ZERO, new Vector3f(RADIUS, RADIUS, RADIUS)));
        //shape.setModelBound(new BoundingBox(Vector3f.ZERO, new Vector3f(RADIUS, RADIUS, RADIUS)));
        shape.rotate(90f*FastMath.DEG_TO_RAD, 30f*FastMath.DEG_TO_RAD, 0f);
        shape.setLocalTranslation(new Vector3f(-20f,RADIUS,-(RADIUS-2)));

        return shape;
    }

I’m trying to get it collided with:

CollisionResults results = new CollisionResults();
myNodesManager.collideWith(area.getWorldBound(), results);

But results is getting between 12 and 40 collisions with itself (there’s nothing more on that area). If I go in with a “BetterCharacterControl” (player) I get between 700 and 1200 collisions per tick with itself and the player.
myNodesManager contains only dynamic spawned things, like the player and the area I spawned and .
I have a total of 13 spatials on my [java]myNodesManager[/java] on that moment so I can’t understand why is it “colliding” with itself so may times.

Thanks for any help.

You can counter these kind of situations by keeping your scene organized. For example you would put all terrrain in a node, all buildings in another node, vegetation in another, etc etc… This will allow you to check collision results in a modular fashion rather than calling on the whole world.

@jayfella said: You can counter these kind of situations by keeping your scene organized. For example you would put all terrrain in a node, all buildings in another node, vegetation in another, etc etc.. This will allow you to check collision results in a modular fashion rather than calling on the whole world.

Yes… I know that basics xD, but the problem I’m having is not because of that, the problem is that I’m getting lots and lots of collisions and I don’t know where they come from. As I said, I have 13 spatials on the node I’m checking the collision with, but I’m getting the sizes I mentioned before, what is really weird.

Well you’re asking “at which points does this box collide with a space that is larger as the box”. The answer is basically: all of them.

@normen said: Well you're asking "at which points does this box collide with a space that is larger as the box". The answer is basically: all of them.

So… when the player goes in the box, it gives me a “collision” for each vertex that the player’s mesh has?

@NemesisMate said: So... when the player goes in the box, it gives me a "collision" for each vertex that the player's mesh has?

You can try this by putting a small box on every collision point.

@normen said: You can try this by putting a small box on every collision point.

Isn’t there a way to check collision between volumes?, so It don’t give a list of all vertex collision but the geometries?, on that way… wouldn’t it be faster internally and easier to work on that kind of situations?.

Thanks for your time… I was stupidly stuck with that :S.

@NemesisMate said: Isn't there a way to check collision between volumes?, so It don't give a list of all vertex collision but the geometries?, on that way... wouldn't it be faster internally and easier to work on that kind of situations?.

Thanks for your time… I was stupidly stuck with that :S.

It’s not giving you a list of all vertexes. But we can’t see what the collisions are. We can’t look at the list and we can’t System.out.println() the geometries, locations, etc… If you do that or if you put little boxes where the collisions are, I think you will see what is happening.

Maybe your object is made up of more than one part? It’s hard to say from here. I will point out that since your box object is rotated 30 degrees, that it’s actual “world bounds” is going to be considerably larger than the original box. World bounds are always axis aligned.

After some more accurated tests I could prove that I’m having as much collisions as triangles on the area being checked. So… If I have 24 triangles on the box that is defining the area and 1008 triangles on the player inside (a default ninja mesh), I get 1032 collisions… if this is the normal behaviour… I’ll work with that.

I checked too that rotations are doing weird things with the bounding volume… :S, is there a way to fix the bounding volume after rotations?

@NemesisMate said: After some more accurated tests I could prove that I'm having as much collisions as triangles on the area being checked. So.. If I have 24 triangles on the box that is defining the area and 1008 triangles on the player inside (a default ninja mesh), I get 1032 collisions... if this is the normal behaviour... I'll work with that.

I checked too that rotations are doing weird things with the bounding volume… :S, is there a way to fix the bounding volume after rotations?

Well, last I checked, mesh to mesh collisions aren’t supported so I have NO idea how you get those results. Maybe it’s because it’s a bounding box.

What are you actually trying to do?

If you just want to check if a player is in an area then see if the player’s location is in that area.

@pspeed said: Well, last I checked, mesh to mesh collisions aren't supported so I have _NO_ idea how you get those results. Maybe it's because it's a bounding box.

What are you actually trying to do?

If you just want to check if a player is in an area then see if the player’s location is in that area.

He uses the world bounds to collide against. And obviously each triangle has to be checked, else how would you know if you collided with a triangle of the mesh? :slight_smile:

@normen said: He uses the world bounds to collide against. And obviously each triangle has to be checked, else how would you know if you collided with a triangle of the mesh? :)

Yeah, but then the box isn’t 24 triangles… it’s a box. (Actually, it would never be 24 triangles anyway so I don’t know.)

Actually, I’m feeling a little time-generous at the second so…

[java]
Vector3f playerLoc =…
Geometry someBox = …
Vector3f local = someBox.worldToLocal(playerLoc, null);
if( someBox.getModelBound().contains(local) ) {
// do stuff
}
[/java]

…or if you want the player to trigger it at some radius:
[java]
Vector3f playerLoc =…
Geometry someBox = …
Vector3f local = someBox.worldToLocal(playerLoc, null);
if( someBox.getModelBound().distanceToEdge(local) < playerRadius ) {
// do stuff
}
[/java]

@pspeed said: Yeah, but then the box isn't 24 triangles... it's a box. (Actually, it would never be 24 triangles anyway so I don't know.)

Maybe it somehow checks each side of the triangles? That would be 24 then. @Momoko_Fan? @NemesisMate, can you make a concise test case for this? (Self-contained, like our test classes)

Well… I think I did you a mess here :S. The results weren’t with a box… I was trying with other shapes, It was with a cylinder the numbers I said. What I wanted to know is why that numbers and I could prove that was because of triangles collisions.

With the check if the player is inside an area… what I really want is to know if a player/entity (even if it’s not a player) gets into the sight of another entity (that area) at any moment. I though on putting a shape representing that area and check collisions inside it to know anything entered there.

Actually, what I do is: I check if there is some collision on that area (with something else than itself) and if so, I cast a ray between the entity owning the area and the entity entered and I check for collisions with the scenery nodes. If I the length of the first collision and the entity (owner of area) is lower than the distance between the entity and the player (entity that enters), it’s out of sight, else, is in.

I don’t really know the best ways to do that… so I’m trying what happens by my mind… :S.

Well, JME doesn’t support mesh to mesh collisions with collideWith() as far as I’ve ever seen. So the only way to collide with a mesh is with a few shapes (ray, bounding sphere, bounding box). And the bounding box will be axis aligned.

I don’t know enough details of your problem to provide actual advice, though. I don’t know what the shapes look like or whatever. It’s a harder kind of problem and may require some extra data structures. Seems like it would be similar to nav meshes, for example. So you may need to keep some separate structure of precalculated visible areas.

The way most games do this is by making some raycast checks from specific points of the players (shoulders, feet, head, hands) to the other players eyes. If nothing collides in between theres a visual connection.

But… directly with all the entities on the game?, I do that but once they enters the area I said before (shape worldbounds)… I think that’s more efficient… or I’m wrong?

@NemesisMate said: But... directly with all the entities on the game?, I do that but once they enters the area I said before (shape worldbounds)..... I think that's more efficient.... or I'm wrong?

Well if you have to expect that they can see them then yes. Most games have a general visibility range so you could exclude all players that have a larger distance than that. I would rather check that based on simple distance than some collision bounding box though, much faster.