Move character control with a* waypoints

hi everyone
i had developed a* in my game.it returns a list of Vector3f to move to target.
my enemy is sinbad spatial and it has the CharacterControl. my question is how to use setWalkDirection with my list of Vector3f to reach the target

thanks.
kareem

You just move in that direction of the point 'til you’re there and then go to the next one…

thanks for your reply
when i pass the point to setWalkDirection it moves very quickly. also i want to set the rotation of the spatial to face each point

this is screenshot
http://imageshack.us/photo/my-images/689/screreen.png/

i need it to walk the green path with rotation

thanks

The walkDirection vector length defines the speed, the view Direction can be set via setViewDirection

2 Likes

The scalar values passed to setWalkDirection, decide how fast it will move each physics tick. So with your vector, just reduce its length, i.e vec.multLocal (0.1f); or something

To face each point, use characterControl.setViewDirection ();

Edit: ninjad :frowning:

1 Like

thanks for the replies

i do what you said.i multiplied the waypoint vector by a scalar to reduce its length until i reach this waypoint (x , z) then go to the next.
but the sinbad never reach the 1st waypoint because it goes backward…!!!

here are the locations that i work with (x, z) :
the sinbad location is (-25 , -55)
first 15 waypoints in astar solution :
(-26,-54) , (-27,-54) , (-28,-54) , (-29,-54) , (-30,-54) , (-31,-54) , (-32,-54) , (-33,-54) , (-34,-53) , (-35,-52) , (-36,-51) , (-37,-50) , (-38,-49) , (-39,-49) , (-40,-49)

here is the code

private Vector3f lastWayPoint = new Vector3f() ;

private int i  ;

private ArrayList<AStarNode> nodes ;    

public void update(float tpf)
{
   Vector3f walkDir = new Vector3f() ;
   
   if(nodes != null)
   {
     try {
        
        System.out.println("current loc = "+getLocation());
    
        System.out.println("a star current= "+lastWayPoint.getX() +" ,,"+lastWayPoint.getZ());

        int currentX = Math.round(characterControl.getPhysicsLocation().x) ;
        
        int currentZ = Math.round(characterControl.getPhysicsLocation().z) ;
        
        if(currentX == lastWayPoint.x && currentZ == lastWayPoint.z)
        {
          System.out.println("reached");
          
          i -- ;  
        }
        
        AStarNode node = nodes.get(i) ;
        
        Vector3f wayPoint = new Vector3f(node.getX(), 0 ,node.getZ()) ;
            
        walkDir = wayPoint.mult(0.01f) ;
        
        lastWayPoint = wayPoint ;
        
        System.out.println("walk dir "+ walkDir);
        
     } catch (Exception e) { // when out of bounds exception
   
          nodes = null ;
     }

   }
   characterControl.setWalkDirection(walkDir);        
}

thanks for your help

thanks everyone. i made it