[SOLVED] World disappear /overload?

Hi my game objects tend to teleport every where in the world even if i just look around not even move
This started to happen after i added a method with a bit complicated claculations,still my cpu and ram aint really get overloaded and my fps jumps from 800 to 0

if(every4Seconds==4){
moveArmiesAndStucks();

        every4Seconds=0;
    }

   public void moveArmiesAndStucks() {
  
    for (ArmyHolder armyHolder : allArmiesHolder.getAllArmiesList()) {
        if (!armyHolder.getEnemyArmysList().isEmpty() || armyHolder.isUnderPlayerControl()) {  //if there is an 
         enemy army (per esclusione dopo if di sopra)
            if (!armyHolder.isUnderPlayerControl()) {
                if (armyHolder.readyToMove()) {
                    armyHolder.setArmyHolderPosition(armyHolder.getArmyHolderPosition().addLocal(
                            armyHolder.getECADirection(armyHolder.getClosestEnemyArmyHolder()).mult(5)
                                    ));

                }
                ArmyHolder closestEnemyArmyHolder = armyHolder.getClosestEnemyArmyHolder();
                if (armyHolder.getArmyHolderPosition().
                        distance(closestEnemyArmyHolder.getArmyHolderPosition()) < 500) {
                    for (UnitsStuck unitsStuck : armyHolder.getUnitsStuckList()) {
                       
                        if (unitsStuck.readyToMove()) {
                            unitsStuck.setUnitStuckLocation(unitsStuck.getUnitStuckLocation().addLocal(
                                    unitsStuck.getECSDirection(closestEnemyArmyHolder).mult(5)));
                           
                            unitsStuck.assignPositionInFormation(closestEnemyArmyHolder, cam);
                        } 
                        else {
                            unitsStuck.assignPositionInFormation(closestEnemyArmyHolder, cam);
                        }
                    }
                }

            }

        } //check if any unit stuck is under players control in the free army when army is not
        else {
            for (UnitsStuck unitsStuck : armyHolder.getUnitsStuckList()) {
                if (unitsStuck.getAttitude() == 4) {
                    unitsStuck.setUnitStuckLocation(player.getLocalTranslation());

                }
            }
        }
    }
    System.out.println("NoblesOrigins.TestAnimationMove.moveArmiesAndStucks()  ENDS");
}

the rest of methods are pretty simple as this and mainly gives movement to ipotetical formations
this method is in update.

Not even move objects ,all Armies exists only theorically no body,soo how it can crush the world? oh and what NAN in localTranslation stands for.
Sorry for a hard question and soo vague ,but im pretty mutch confused as well :frowning: every thing was working fine,and now blows up in the most uncommon way

Seems like nodes and geometries i cant see still have LocalTranslation when i cant see me
Seems world dose not disappera its only every movement in the world get crazy and my cam get teleported in nowhere

Sounds like maybe you are modifying the JME constants directly or directly modifying the local translations of the Spatials by handing their Vector3f off to something else.

This is definitely not a problem in JME code… all in your own code that we can’t see.

ok i will try to paste all method and methods by may be long and not really cute :wink:

 public class ArmyHolder {
int factionInt;
ArrayList<ArmyHolder> enemyArmysList= new ArrayList<ArmyHolder>();
ArrayList<UnitsStuck> unitsStuckList=new ArrayList<UnitsStuck>();
boolean underPlayerControl;
boolean followPlayer;
Vector3f armyHolderPosition;



public Vector3f getECADirection(ArmyHolder enemyArmy){
    Vector3f direction=
 enemyArmy.getArmyHolderPosition().subtract(armyHolderPosition);
    return direction;
}

public ArmyHolder getClosestEnemyArmyHolder(){
    ArmyHolder closestEnemyArmyHolder = this.getEnemyArmysList().get(0);
    for(ArmyHolder enemyArmyHolder:this.getEnemyArmysList()){
      if(this.armyHolderPosition.distance(enemyArmyHolder.getArmyHolderPosition())>
              this.armyHolderPosition.distance(closestEnemyArmyHolder.getArmyHolderPosition())){
          closestEnemyArmyHolder=enemyArmyHolder;
    }
                 }
    return closestEnemyArmyHolder;
}

public boolean readyToMove(){
    boolean ready=true;
    for (UnitsStuck unitsStuck:unitsStuckList){
        if(this.armyHolderPosition.distance(unitsStuck.getUnitStuckLocation())>1000){
            ready=false;
        }
    }
    return ready;
}
}

other class

 public class UnitsStuck {
public ArrayList<SpawnedUnitClass> spawnedUnitsList = new ArrayList<SpawnedUnitClass>();
public ArrayList<SpawnedKnightClass> spawnedKnightList= new ArrayList<SpawnedKnightClass>();
public PlayerClass player;
public ArrayList<UnitsStuck>commandedStucksList= new ArrayList<UnitsStuck>();//who i command
public ArrayList<UnitsStuck>commanderStucksList=new ArrayList<UnitsStuck>();// who commands me
public UnitsStuck target;
public ArrayList<UnitsStuck>targetedBy=new ArrayList<UnitsStuck>();
public Node banner;
public int formation;

public Vector3f unitStuckLocation;
public int attitude;//follow player or search and attack staks for now 1 attack 2 deffend 3 stay/do nothing 4 follow player
public int fighting;//if 1 move out look for enemy (probably UnitStuck target) and fight. if 2 just follow banner

public Vector2f muovereDiLAtoPostoFormazione(Vector3f vector3f){

Vector2f movimento = new Vector2f(vector3f.getZ(), vector3f.getX());
return movimento;
}

//works each time formation moves
public void assignPositionInFormation(ArmyHolder closestEnemyArmyHolder,Camera camera){
    //lets say formation is squar
    
    
///spawn common soldiers
    //round to less in row
    //round to excess for the number of rows
    
    if(target!=null&&this.getAttitude()!=4){
        //give nobles             and commoners positions
        APFNS(closestEnemyArmyHolder, APFCS(closestEnemyArmyHolder,0));
    }
  
    else{
        assignPositionFCSByPlayer(assignPositionFNSByPlayer(0, camera), camera);
    }

}
public int assignPositionFCSByPlayer(int lastRow,Camera camera){
    
    int soldiersId=0;
   
    for (int l = 0; l < (int) Math.ceil(Math.sqrt(spawnedUnitsList.size()))-1; l++) {
            //per uomeni in fila
            for (int i = (int) Math.floor(Math.sqrt(spawnedUnitsList.size())); i > 0; i--) {
               
                for (int j = (int) Math.floor(Math.sqrt(spawnedUnitsList.size()))/2; j >0; j--) {
                    spawnedUnitsList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()-
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getX()*j,
     this.getUnitStuckLocation().getY()+
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getY()*j
             )
        .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-camera.getDirection().getX()
        , this.getUnitStuckLocation().getY()-camera.getDirection().getZ()).mult(l+lastRow))
                    ); 
        soldiersId++; 
                }
                 //seconda meta
                for (int j = 1; j <(int) Math.floor(Math.sqrt(spawnedUnitsList.size()))/2; j++) {
                    spawnedUnitsList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()+
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getX()*j,
     this.getUnitStuckLocation().getY()-
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getY()*j
             )
                 .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-camera.getDirection().getX()
        , this.getUnitStuckLocation().getY()-camera.getDirection().getZ()).mult(l+lastRow))           
                    );
                    soldiersId++;  
                }
             
            }//qui finisce formazione non nobile
            lastRow++;  
            }
    return lastRow;
}

public int assignPositionFNSByPlayer(int lastRow,Camera camera){
   
    
    int soldiersId=0;
   
    for (int l = 0; l < (int) Math.ceil(Math.sqrt(spawnedKnightList.size()))-1; l++) {
           
            for (int i = (int) Math.floor(Math.sqrt(spawnedKnightList.size())); i > 0; i--) {
              
                for (int j = (int) Math.floor(Math.sqrt(spawnedKnightList.size()))/2; j >0; j--) {
                    spawnedKnightList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()-
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getX()*j,
     this.getUnitStuckLocation().getY()+
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getY()*j
             )
        .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-camera.getDirection().getX()
        , this.getUnitStuckLocation().getY()-camera.getDirection().getZ()).mult(l+lastRow))
                    ); 
        soldiersId++; 
                }
               
                for (int j = 1; j <(int) Math.floor(Math.sqrt(spawnedKnightList.size()))/2; j++) {
                    spawnedKnightList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()+
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getX()*j,
     this.getUnitStuckLocation().getY()-
             this.muovereDiLAtoPostoFormazione(camera.getDirection()).getY()*j
             )
                 .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-camera.getDirection().getX()
        , this.getUnitStuckLocation().getY()-camera.getDirection().getZ()).mult(l+lastRow))           
                    );
                    soldiersId++;  
                }
             
            }
            lastRow++;  
            }
    return lastRow;
}


/**This method makes Assign Position In Formation to Commoners soldiers in a Squ
 * @param closestEnemyArmyHolder gives direction
 * @param lastRow just in case they are not first to get positions
 * @return needed to spawn noble unit behinde the rows of commoners */
public int APFCS(ArmyHolder closestEnemyArmyHolder,int lastRow){
    ///spawn common soldiers
    //round to less in row
    //round to excess for the number of rows
   
    int soldiersId=0;
  
    for (int l = 0; l < (int) Math.ceil(Math.sqrt(spawnedUnitsList.size()))-1; l++) {
            
            for (int i = (int) Math.floor(Math.sqrt(spawnedUnitsList.size())); i > 0; i--) {
              
                for (int j = (int) Math.floor(Math.sqrt(spawnedUnitsList.size()))/2; j >0; j--) {
                    spawnedUnitsList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()-
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getX()*j,
     this.getUnitStuckLocation().getY()+
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getY()*j
             )
        .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()- 
            this.getECSDirection(closestEnemyArmyHolder).getX()
        , this.getUnitStuckLocation().getY()-this.getECSDirection(closestEnemyArmyHolder).getZ()).mult(l+lastRow))
                    ); 
        soldiersId++;
                }
               
                for (int j = 1; j <(int) Math.floor(Math.sqrt(spawnedUnitsList.size()))/2; j++) {
                    spawnedUnitsList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()+
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getX()*j,
     this.getUnitStuckLocation().getY()-
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getY()*j
             )
                 .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()- 
           this.getECSDirection(closestEnemyArmyHolder).getX()
        , this.getUnitStuckLocation().getY()-this.getECSDirection(closestEnemyArmyHolder).getZ()).mult(l+lastRow))           
                    );
                    soldiersId++;  
                }
             
            }
            lastRow++;  
            }
    return lastRow;
}

public int APFNS(ArmyHolder closestEnemyArmyHolder,int lastRow){
    
    int soldiersId=0;
     
            for (int l = 0; l < (int) Math.ceil(Math.sqrt(spawnedKnightList.size()))-1; l++) {
           
            for (int i = (int) Math.floor(Math.sqrt(spawnedKnightList.size())); i > 0; i--) {
               
                for (int j = (int) Math.floor(Math.sqrt(spawnedKnightList.size()))/2; j >0; j--) {
                    spawnedUnitsList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()-
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getX()*(j+2),
     this.getUnitStuckLocation().getY()+
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getY()*(j+2)
             )
        .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-this.getECSDirection(closestEnemyArmyHolder).getX()
        , this.getUnitStuckLocation().getY()-this.getECSDirection(closestEnemyArmyHolder).getZ()).
                mult(l+lastRow+1))
                    ); 
        soldiersId++; //make each soldier been selected only once no metter how many for row or for men in row
                }
                 
                for (int j = 1; j <(int) Math.floor(Math.sqrt(spawnedKnightList.size()))/2; j++) {
                    spawnedKnightList.get(soldiersId).setPositionInFormation( 
            new Vector2f(
     this.getUnitStuckLocation().getX()+
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getX()*(j+2),
     this.getUnitStuckLocation().getY()-
             this.muovereDiLAtoPostoFormazione(this.getECSDirection(closestEnemyArmyHolder)).getY()*(j+2)
             )
                 .subtractLocal(new Vector2f(this.getUnitStuckLocation().getX()-this.getECSDirection(closestEnemyArmyHolder).getX()
        , this.getUnitStuckLocation().getY()-this.getECSDirection(closestEnemyArmyHolder).getZ()).
                         mult(l+lastRow+1))           
                    );
                    soldiersId++;  
                }
             
            }
            lastRow++;
            }
            return lastRow;
}

public boolean readyToMove(){
    boolean ready=true;
    if(!spawnedUnitsList.isEmpty()){
    for (SpawnedUnitClass spawnedUnitClass:spawnedUnitsList){
        if(this.unitStuckLocation.distance(spawnedUnitClass.getActualUnitPosition())>60){
            ready=false;
        }
    }
    }
    
    if(!spawnedKnightList.isEmpty()){
    for (SpawnedKnightClass spawnedKnightClass:spawnedKnightList){
        if(this.unitStuckLocation.distance(spawnedKnightClass.getActualUnitPosition())>60){
            ready=false;
        }
    }
    }
    return ready;
}
/**
 * gives EnemyClosestUnitStuck as Direction
 * @param enemyArmy
 * @return 
 */
public Vector3f getECSDirection(ArmyHolder enemyArmy){
Vector3f direction=
 this.getClosestEnemyUnitStuck(enemyArmy).
      getUnitStuckLocation().subtract(this.getUnitStuckLocation()).normalize();
    return direction;
}

/**
 * gives direction to any Vector3f coordinates ,a general method to get direction
 * @param vector3f
 * @return 
 */
public Vector3f getDirection(Vector3f vector3f){
Vector3f direction=
 vector3f.subtract(this.getUnitStuckLocation()).normalize();
    return direction;
}


public UnitsStuck getClosestEnemyUnitStuck(ArmyHolder enemyArmy){
    UnitsStuck closestEnemyUnitStuck = enemyArmy.getUnitsStuckList().get(0);
    for(UnitsStuck enemyUnitsStuck:enemyArmy.getUnitsStuckList()){
      if(this.getUnitStuckLocation().distance(enemyUnitsStuck.getUnitStuckLocation())>
              this.getUnitStuckLocation().distance(closestEnemyUnitStuck.getUnitStuckLocation())){
          closestEnemyUnitStuck=enemyUnitsStuck;
    }
                 }
    this.setTarget(closestEnemyUnitStuck);
    closestEnemyUnitStuck.addToTargetedBy(this);
    return closestEnemyUnitStuck;
}

/**
 * collision of unit to an other unit if moves to next step
 */
public boolean unitToUnitCollision(boolean freeWay,SpawnedUnitClass unitClass,Vector3f willBeThere){
    for(SpawnedUnitClass otherUnits: this.getSpawnedUnitsList()){
          if(willBeThere.
                  distance(otherUnits.getActualUnitPosition())<1){
              freeWay=false;
          }
      }
    for(SpawnedKnightClass otherUnits: this.getSpawnedKnightList()){
          if(willBeThere.
                  distance(otherUnits.getActualUnitPosition())<1){
              freeWay=false;
          }
      }
    return freeWay;
}



public void moveToFP(){
  for(SpawnedUnitClass unitClass: this.getSpawnedUnitsList()) {
      boolean freeWay=true;
      Vector2f vector2fDirection=
      unitClass.getPositionInFormation().
              subtract(unitClass.getActualUnitPosition().getX(),
              unitClass.getActualUnitPosition().getY())
              .normalize();
      Vector3f willBeThere=unitClass.getActualUnitPosition().add(vector2fDirection.getX(),
                  0.f, vector2fDirection.getY());
      freeWay = unitToUnitCollision(freeWay ,unitClass,  willBeThere);
      freeWay=unitToUnitCollision(freeWay,unitClass, willBeThere);
      if(freeWay==false){  
              willBeThere= unitClass.getActualUnitPosition().add(//trygo right and forward
                      vector2fDirection.getX()/10*.7f+vector2fDirection.getY()/10*.7f,
                  0.f, vector2fDirection.getY()/10*.7f-vector2fDirection.getX()/10*.7f);
       freeWay = unitToUnitCollision(freeWay ,unitClass,  willBeThere);
      freeWay=unitToUnitCollision(freeWay,unitClass, willBeThere);
      if(freeWay==false){  
          willBeThere= unitClass.getActualUnitPosition().add(//trygo left and forward
                      vector2fDirection.getX()/10*.7f-vector2fDirection.getY()/10*.7f,
                  0.f, vector2fDirection.getY()/10*.7f+vector2fDirection.getX()/10*.7f);
       freeWay = unitToUnitCollision(freeWay ,unitClass,  willBeThere);
      freeWay=unitToUnitCollision(freeWay,unitClass, willBeThere);
          if (freeWay==false) {
              
          } else {
              unitClass.setActualUnitPosition(unitClass.getActualUnitPosition().add(getDirection(willBeThere)));
          unitClass.getNodeBody().setLocalTranslation(unitClass.getActualUnitPosition().add(getDirection(willBeThere)));   
          }
      }
      else{
          
       unitClass.setActualUnitPosition(unitClass.getActualUnitPosition().add(getDirection(willBeThere)));
          unitClass.getNodeBody().setLocalTranslation(unitClass.getActualUnitPosition().add(getDirection(willBeThere)));   
          
      }
          }
          else{
              unitClass.setActualUnitPosition(unitClass.getActualUnitPosition().add(
                      vector2fDirection.getX()/100,
                      0,
                      vector2fDirection.getY()/100));
              
              unitClass.getNodeBody().setLocalTranslation(unitClass.getActualUnitPosition());
          }  
  } 
}

The main problem is my player node or may be cam seems to start fly around the world when i activate this method to localTranslation (Nan,89,Nan) while from what i can see after alot of tests the rest of the world actually remains where it is

When a position gets NaNs in it then it’s something you did wrong somewhere… usually you mess up a rotation somehow.

Em in my code i have ArmyHolderClass setLocalTranslation()
camn it be changing a nodes translation ?
i mean if i turn off this method players node works perfectly ,if i use it it breaks ,but method it self use no players node at all … soo i just cant get it

NoblesOrigins.TestAnimationMove.moveArmiesAndStucks() Start!!!(1054.12, 486.0, 1068.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.getArmyHolderPosition()(1054.12, 486.0, 1068.85)
fpsSpawnedUnitsHolder.ArmyHolder.getClosestEnemyArmyHolder() 1 (1054.12, 486.0, 1068.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.getArmyHolderPosition()(1054.12, 486.0, 1068.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.getArmyHolderPosition()(1054.12, 486.0, 1068.85)
fpsSpawnedUnitsHolder.ArmyHolder.getClosestEnemyArmyHolder() 2 (1054.12, 486.0, 1068.85)
fpsSpawnedUnitsHolder.ArmyHolder.getECADirection()1(1054.12, 486.0, 1068.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.getArmyHolderPosition()(1054.12, 486.0, 1068.85)
fpsSpawnedUnitsHolder.ArmyHolder.getECADirection()2(1054.12, 486.0, 1068.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.setArmyHolderPosition()1(1204.12, 486.0, 1218.85)
NoblesOrigins.Classes.FPSAllConcernsBattle.fpsSpawnedUnitsHolder.ArmyHolder.setArmyHolderPosition() 2(1204.12, 486.0, 1218.85)
NoblesOrigins.TestAnimationMove.moveArmiesAndStucks() End!!!(1204.12, 486.0, 1218.85)

some incredible stuff ,it happens this way but i have no idea on why?!

FUCK ME AT SQUARE !! i found my mistake !!!
not used " new "a few times :frowning:
sorry for taking your time

oh by the case could you suggest any way to transform LocalRotation in Vector 3 f?

http://javadoc.jmonkeyengine.org/com/jme3/math/Quaternion.html#toAngles-float:A-

http://javadoc.jmonkeyengine.org/com/jme3/math/Quaternion.html#mult-com.jme3.math.Vector3f-

THNX!! :slight_smile: