# "Patrolling"

Hi,

If we use addLocal in moving from one place to another, does the difference between two points have to be greater than 0 i.e. can I go to a place turn around and travel back the same path?? I tried doing it but in such cases the object stays at the same place. An example code is provided below.

```     private Vector3f enemyPos = new Vector3f(), enemyMovement = new Vector3f(0.5f, 0f, 0f), enemyMovementBack = new Vector3f(-0.5f, 0f, 0f);             //current translation is (-60, 15, 40)             enemyNode.lookAt(new Vector3f(64, 15, 40), Vector3f.UNIT_Y); //place where we want to go             enemyPos.set(enemyNode.getLocalTranslation());                               enemyPos.addLocal(enemyMovement.mult(0.08f));             enemyNode.setLocalTranslation(enemyPos);                            if(enemyNode.getLocalTranslation().getX() >= 64f)            {                enemyNode.setLocalTranslation(new Vector3f(64f, 14f, 40f));     //Vector we want to go to and return from                enemyNode.lookAt(new Vector3f(-60, 15, 40), Vector3f.UNIT_Y);      // Vector we came from and return to                 }                      enemyPos.set(enemyNode.getLocalTranslation());                         enemyPos.addLocal(enemyMovementBack.mult(0.08f)); //movement in the negative direction           enemyNode.setLocalTranslation(enemyPos);           System.out.println(enemyNode.getLocalTranslation());          if(enemyNode.getLocalTranslation().getX() <= -60f)         {             enemyNode.setLocalTranslation(new Vector3f(-60f, 14f, 40f));   //when we reach where we started from we stop             enemyNode.lookAt(new Vector3f(64, 15, 50), Vector3f.UNIT_Y); //turn to where we want to head         }                 scene.updateGeometricState(0f, true);            System.out.println(enemyNode.getLocalTranslation()); ```

Also, any heads up on how to use picking on .3ds files(post in Graphics) will be greatly appreciated as it is greatly stalling my AI scripting.

Make sure you are using your vectors the right way.

I don't see anything wrong right away, but generally this is an issue with most people.

The problem is that both movements +ve and -ve are carried out simulatenously so it stays at the same place. When I figure out how to solve it I'll post the code.

Thanks - Have you got any idea on what am I doing wrong with picking - why it picks out parts of the .3ds object instead of the node it is attached to??

Dev

try

`results.getPickData(i).getTargetMesh().getParentGeom().getParent().getName()`

`results.getPickData(i).getTargetMesh().getParentGeom().getName()`

try to debug the code and c how deep ur model node is. i cant remember exactly for 3ds, but for collada, its 3 levels deep down.

Hey,

I discovered a cool way of patrolling instead of using add local and optimized it so this movement can stop when player gets in line of sight XD. The code is as follows:

``` private float movementSpeed = -20f; private boolean movementEnemy(boolean noEnemyInSight)     {                 if(noEnemyInSight)         {             enemyNode.getLocalTranslation().x += movementSpeed * 0.0117;                     if (enemyNode.getLocalTranslation().x > 64)             {                 enemyNode.getLocalTranslation().x = 64;                 movementSpeed *= -1;                 enemyNode.lookAt(new Vector3f(34, 15, 40), Vector3f.UNIT_Y);             }                         else if (enemyNode.getLocalTranslation().x < -60)             {                 enemyNode.getLocalTranslation().x = -60;                 enemyNode.lookAt(new Vector3f(24, 15, 50), Vector3f.UNIT_Y);                 movementSpeed *= -1;             }                         return true;         }                 else         {             enemyNode.lookAt(player1.getLocalTranslation(), Vector3f.UNIT_Y);             shootAtPlayer(enemyNode);                   return false;                        }       } ```

@basixs - getParentGeom().getParent().getName() returns object3 - object3 is the node and is also the string name of the parent.

@neakor - forgive my ignorance but does it matter how many levels does a 3ds file have - if you attach it to a Node then on bounding collision picking it should surely detect the bound of the Node instead of the object within it. Will work on it and inform you if I make any progress. Appreciate if senior members have come across this problem and know anything!! :)
it should surely detect the bound of the Node instead of the object within it

how should jme know at which level to stop?
HamsterofDeath said:

it should surely detect the bound of the Node instead of the object within it

how should jme know at which level to stop?

what he said lol

the problem is that yes idealy it will just pick out the bounding, but node without any geomBatch doesnt have a bound, so technically u r still picking the bounding of the object. the problem comes when u go above the level of ur object, ur getParent() method might have already went up to the parent of the node of the object. in worst case, the method may even return the rootNode. and if u try to move the rootNode, obviously u wont get ur desired effect.

For the time being I found a temporary solution and not the most effective where I detect if the ray hits the player and it does not hit it before the wall node, in this case I execute specific action(code listed below). But surely you are not telling me that the graphics part of jME, which is quite advanced and contains really good functionalities overall, has not taken this into account? Or there is no other way of handling .3ds files while picking??

By the way thanks a lot to basixs, neakor and HamsterofDeath for your invaluable contributions. Your explanations help me figure out the problem.

``` private boolean lineOfSight(Node node)     {         Ray ray = new Ray(node.getLocalTranslation(), node.getLocalRotation().getRotationColumn(2));         PickResults results = new BoundingPickResults();                scene.findPick(ray,results);                 Ray ray1 = new Ray(new Vector3f(node.getLocalTranslation().x + 1f, node.getLocalTranslation().y, node.getLocalTranslation().z), node.getLocalRotation().getRotationColumn(2));         PickResults results1 = new BoundingPickResults();                scene.findPick(ray1,results1);                 Ray ray2 = new Ray(new Vector3f(node.getLocalTranslation().x - 1f, node.getLocalTranslation().y, node.getLocalTranslation().z), node.getLocalRotation().getRotationColumn(2));         PickResults results2 = new BoundingPickResults();                scene.findPick(ray2,results2);                 //System.out.println(player1.getWorldBound().);                 if((player1.getWorldBound().intersects(ray) && results.getPickData(3).getTargetMesh().getParentGeom().getParent().getName()         != "Walls")  )         {                                       System.out.println("!!!!!!!!!!!!!Enemy Detected - Alert!!!!!!!!!!!!!!");             shootAtPlayer(node);             return true;                               }                 else if((player1.getWorldBound().intersects(ray1) && results1.getPickData(3).getTargetMesh().getParentGeom().getParent()         .getName() != "Walls"))         {             shootAtPlayer(node);             return true;         }                 else if((player1.getWorldBound().intersects(ray2) && results2.getPickData(3).getTargetMesh().getParentGeom().getParent()         .getName() != "Walls"))         {             shootAtPlayer(node);             return true;         }                 else         {             return false;         }             } ```

p.s. I had a look at the screenshot for your game HamsterofDeath and it looks highly professional and awesome. Mine is much more basic and a university project.

Thanks for the thanks

your game HamsterofDeath and it looks highly professional and awesome

*bow*