# Walk character minimal path

Hello ,help help !
I 'm trying to move an Sinbad character from a location to Another location in the physics space or more clearly Iβm doing the AI movement, someone correct me, if I think wrong.

Now I calculate the minimal path and set the physics location in this way :

[java]
//update loop
@Override
public void simpleUpdate(float tpf) {
// player
camDir = cam.getDirection().clone().multLocal(0.6f);
camLeft = cam.getLeft().clone().multLocal(0.4f);
walkDirection.set(0,0,0);
if(left)
if(right)
if(up)
if(down)
player.setWalkDirection(walkDirection);
cam.setLocation(player.getPhysicsLocation());

``````	//oto
}

Vector3f walk = new Vector3f();
//physics position
currentX = character.getPhysicsLocation().x;
currentZ = character.getPhysicsLocation().z;

if(currentX == -340 &amp;&amp; currentZ == 50 ){
//destination
System.out.println("********************* POSIZIONE RAGGIUNTAAAAAAAA *************************");
}
else if(!graphLand.getMininalPath().isEmpty()){

currentX = graphLand.minimalPath.getFirst().row;
currentZ = graphLand.minimalPath.getFirst().col;

//--------------------------------------------
/*
walk.x = ?    &lt;&lt;&lt;----- PROBLEM
walk.z = ?    &lt;&lt;&lt;-----
if (!character.onGround()) {
airTime = airTime + tpf;
} else {
airTime = 0;
}
if (walk.length() == 0) {
if (!"IdleTop".equals(animationChannel.getAnimationName())) {
animationChannel.setAnim("IdleTop", 1f);
}
} else {
character.setViewDirection(walk);
if(airTime&gt; .5f){
if(!"RunBase".equals(animationChannel.getAnimationName())){
animationChannel.setAnim("RunBase", 0.7f);
}
}
}
character.setWalkDirection(walk);
*/
//-------------------------------------------------
//remove the cell occupated
graphLand.getMininalPath().removeFirst();
//set physics location
character.setPhysicsLocation( new Vector3f( currentX ,character.getPhysicsLocation().y,currentZ ) );
}
}
``````

[/java]

The result is that the Character is moved so Iβm happy , but I donβt know how to set/modify the walkX and walkZ for walk of character??

find the direction in world space (destination - current) and that is the walk direction vector. If you want to accumulate movement, then just add the 2 βwalkβ direction vectors together (I notice you already set the walk direction previously, only the last one will take effect)

If you want to accumulate movement ?? I donβt understand scuse me, how I consider the cell of minimal path when I set the walk?
I may have been unclear,I wanna that for every cell (x,z)of path, the character walk

please can you explain me clearly and speak about the code β¦Itβs my first time

[java]
β¦
else if(!graphLand.getMininalPath().isEmpty()){
//cell to occupy
currentX = graphLand.minimalPath.getFirst().row;
currentZ = graphLand.minimalPath.getFirst().col;

``````                    //βββββββββββββββ
/*
walk.x = ?    &lt;&lt;&lt;ββ PROBLEM
walk.z = ?    &lt;&lt;&lt;ββ
if (!character.onGround()) {
airTime = airTime + tpf;
} else {
airTime = 0;
}
if (walk.length() == 0) {
if (!βIdleTopβ.equals(animationChannel.getAnimationName())) {
animationChannel.setAnim(βIdleTopβ, 1f);
}
} else {
character.setViewDirection(walk);
if(airTime&gt; .5f){
if(!βRunBaseβ.equals(animationChannel.getAnimationName())){
animationChannel.setAnim(βRunBaseβ, 0.7f);
}
}
}
character.setWalkDirection(walk);
*/
//ββββββββββββββββ-
//remove the cell occupated
graphLand.getMininalPath().removeFirst();
//set physics location
character.setPhysicsLocation( new Vector3f( currentX ,character.getPhysicsLocation().y,currentZ ) );
}
``````

[/java]

The direction can be calculated by subtracting the current position from the destination.

[java]
Vector3f destination = β¦
Vector3f currentPos = β¦

Vector3f direction = destination.subtract(currentPos);
[/java]

The specifics exactly on how to get a character from position A to position B at a constant speed is something I have not toyed with yet, but a starting point would be:

[java]
Vector3f walkSpeed = new Vector3f(0, 0, 0);

if (direction.getX()) > .1f) walkSpeed.addLocal(1f, 0, 0);
if (direction.getZ()) > .1f) walkSpeed.addLocal(0, 0, 1f);
[/java]

Up till direction you were doing fine.

For constant speed just do direction.normalizeLocal().multLocal(speed)

1 Like