Overlapping Objects (Collision / Intersection fundamentals)

Hey. Sorry, if the question is dumb.



I’ve tried following the tutorial, but still experienced failures every now and again.

  1. I wanted to see if a given entity intersects with the ground to lift it a bit if it’s needed. Trying terrain.collideWith(entity,collisionResults) yielded nothing useful. Used a dirty workaround, stumbled on another problem:
  2. Want to check for objects, that a bot can potentially see. Therefore would like to obtain a list of entities within a given radius. Wanted to use create a sphere-shaped geometry and do a collision test - UnsupportedCollisionException regardless of whether I attached the sphere to the root or I haven’t and so on.



    Therefore I assume I must be missing something fundamental about the concept. There has to be some list of a prerequisites that I fail to meet, can’t find in the docs and fail to guess. If I was to ask one yes/no type of question, it would be something like this:

    is it possible to obtain a list of intersections between a root node and a geometry being some descendant of that root node?



    thanks in advance for any help,

    best regards,

    Tomek



    Edit:

    After some debugging, it seems that my actions force the app into some inconsistent state: Geometry’s WorldBound stays null util the next render, afterwards the collision results are found, but all of them have nulls as colliding geometries. What do I keep doing wrong?

For see the objects that a bot can potentially see you can use a GhostControl.

I don’t know if it’s the best aproach.



More info: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics



GhostControl:

Use for collision and intersection detection between physical entities. A GhostControl is non-solid and invisible, and it moves with the Spatial it is attached to. Use this for interactive game elements that do not have a visible solid Geometry: A monster’s “aggro radius”, motion detectors, photoelectric alarm sensors, poisonous or radioactive perimeters, life-draining ghosts, etc.



I hope this will help you.

Thanks for the answer :slight_smile:

Well, initially I wanted to go with a ghost control. However, as the bots can be added dynamically, they belong to a certain collision group (I played with code a bit to make them bounce off each other) that has to be detectable by ghosts. When I tried a ghost control, it kept detecting collisions with the spatial being the owner of the control, slowing the performance down as well. So here I am, looking for a workaround :confused:



I guess that for now I will just evaluate the distance ‘by hand’ and return an approproiate set of Nodes…



EDIT:

from BoundingSphere:

public int collideWith(Collidable other, CollisionResults results) {

if (other instanceof Ray) {

Ray ray = (Ray) other;

return collideWithRay(ray, results);

} else {

throw new UnsupportedCollisionException();

}

}

So I was heading in a wrong direction. Is there any option of making a ghostControl “ignore” its owner then? (A way that would however enable this control to detect other, similiar entities and wouldn’t require using a separate physicsSpace for each)

I’m sorry but I’m a bit confused with your answer. I’m not very sure what is your goal.



I’ve tried ghost control but in a very easy application.

I’ve some objects that I want to know if there is a collision between them, so every one has a ghost control.

My main application implements a PhysicsCollisionListener and has a bulletAppState.

Then in the fuction provided by the PhysicsCollisionListener → public void collision(PhysicsCollisionEvent event) I read the nodes involved in a collision by event.getNodeA() and event.getNodeB() and decide what stuff do.

If you have different collision groups the GhosControl have differen collidable groups, use

yourbot.getControl(GhosControl.class).setCollisionGroup(GhostControl.COLLISION_GROUP_01) and

setCollideWithGroups.



The fact it’s that I haven’t tried those fuctions but they seem to do what you are looking for (if I have understand you).