Agro Detection (Sphere around a Spatial would be the best solution or not ? )

Hi everyone , i’ve been searching all along with no answer ,

How do you put a Sphere around a spatial ( 3D model imported with Ogre XML ) and set it a big radius ?

I have a PhysicsCharacterNode controlled that i want to collide with a Spatial but far away from it , so i want a big radius sphere.

Thanks a lot ^^

Didn’t you see the radius attribute of the sphere constructor?

public Sphere(int zSamples, int radialSamples, float radius)

Yes i saw it , i was just explaining what i wanted to do , you didn’t get my point :slight_smile:

I’m seeking for a way to load a sphere around a Model , how do you do that ?

you create a sphere with the radius you want to, attach it to the model Node, then position it at the exact same place as the model.


Spatial chado;

Boundingsphere ennemy;

ennemy = new BoundingSphere();




What am i doing wrong here ?

Everything. You sure you did the tutorials? You seem to have no idea what you are doing there…

i did the first 10 tutos i never seen an example with volumes around models .what tuto are u talking about ?

Well the one expaining what a spatial or node is for example, you cannot attach something to a bounding volume… Also what do you want to achieve by setting a big bounding volume? It will only yield wrong results and make the culling not work properly. If you want the character to be bigger you have to make the collision shape bigger. If you want to check for collisions far away you can simply use PhysicsGhostNode or use the collideWith method with a new Geometry with the correct size.

i want to have an "aggro gestion " like in MMO that’s why i wanted to do that ,do you have another solution to propose ? i’m open with it :slight_smile: thanks a lot

I tried to follow your advice normen :

I filtered only what are we interested for here


import com.jme3.collision.CollisionResults;

private PhysicsCharacterNode character;

private PhysicsNode agro;

private PhysicsGhostNode agroinvisible;

public void Collisioncombat(){


CollisionResults results = new CollisionResults();

character.collideWith(agro, results);

if (results.size() > 0) {

System.out.println(“Collide OK”);


System.out.println(“No colliding”);



private void initGhostObject(){

Vector3f halfExtents = new Vector3f(3, 4.2f, 1);

Material mat = new Material(getAssetManager(), “Common/MatDefs/Misc/WireColor.j3md”);

mat.setColor(“m_Color”, ColorRGBA.Red);

agroinvisible = new PhysicsGhostNode(new BoxCollisionShape(halfExtents));





public void simpleUpdate(float tpf){




// And this is how i declared my character and the box

character = new PhysicsCharacterNode(new CapsuleCollisionShape(1.5f, 2f ,1), 1f);

agro = new PhysicsNode(new BoxCollisionShape(new Vector3f(20.5f, 10f ,10)), 1f);



and ERROR :

24 nov. 2010 22:35:09 handleError

GRAVE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

Thanks for the answer

danath said:
i want to have an "aggro gestion " like in MMO that's why i wanted to do that ,do you have another solution to propose ? i'm open with it :) thanks a lot

I'm not an expert on JME but I can tell you that you are not using the best approach for what you are describing. You definitely should not add geometry to check something like a distance. Instead you will want to check if the character comes within the distance you defined. Without needing a direction this technically becomes a radius, because you don't care what angle the approach comes from. If you need a direction (for example if the enemy has to be facing the character) then your "radius" needs to be the area in-between 2 angles of the enemy POV.

But how can you detect the distance if you don’t use geometry ?

Anyway that’s very interesting what are you saying , could you give me an example ? ( in pseudo code or in java will be okay )

Thanks in advance :wink: !

When I said use geometry I meant not to draw a Sphere around the enemy. You will have 2 Nodes. 1 Being the player and 1 being the enemy. The enemy will have a model just like the player, however to do this “detection” or “Aggro” you should not draw a large sphere around the enemy player. Instead you will take the position of the enemy + the radius you want and compare it against the current player’s position.

That’s a great idea it’s safer than everything else thank you very much … but how do i manage to set a radius without any sphere ? ( sorry i’m learning here , i never done that before ) , maybe i can compare with the cosinus and sinus position ? what do you think about it ?

I don’t know if JME has it build in, but I have built some radars inside of other games/tools before. What I did was take the 2 positions and find the distance through the distance formula. Lets say the distance between Enemy and player is 50 units (this is without the radius). Now you just subtract the final distance (50 units) - the number of units you want your radius to be (10 units). This means your player is only 40 units away. This is the simplest approach, it will get a little tougher when you want your enemy to only be facing a certain direction. I suggest you brush up on your math though.

i’ll work out , thanks for the idea again :wink:

that’s what i did :



System.out.println("Collision OK “);

}else System.out.println(“Character in X :”+character.getLocalTranslation().x+ " ennemy in Y :”+mymodel.getLocalTranslation().x);



It’s working on a side but not on another , anyone has an idea for setting a radius here ?

This can’t work.

you are computing the difference between the x values of the positions and expect it will give you a distance…

just think about an example character x=-30, mymodel x= -60. You’ll get your collision OK but objects are nowhere near.

You really need to read about math and vectors, I recommend this chapter of the documentation :

For your problem, to compute the distance between 2 positions, you need a vector that goes from one position to the other, and compute its distance.

First compute the difference of the vectors

Vector3f sub = character.getLocalTranslation().subtract(mymodel.getLocalTranslation());

the order does not matter because we are going to compute the lenght.

To do that, there is a convenient lenght() method in Vector3f, so the lenght is sub.length()

So your code should look like that :


System.out.println("Collision OK “);


System.out.println(“Character in X :”+character.getLocalTranslation().x+ " ennemy in Y :”+mymodel.getLocalTranslation().x);


Thank you for your patience , i’m learning a lot in this forum thanks of your kindness guys , i’m gonna read thoses tutorials thank you nehon.