Пример #1
0
  public Vector2f getPosition() {
    if (currentPosition == null) {
      if (isOnLastPoint()) return path.getPoint(index);

      Vector2f p0 = path.getPoint(index);
      Vector2f p1 = path.getPoint(index + 1);

      Vector2f direction = p1.copy().sub(p0).normalise();

      currentPosition = p0.copy().add(direction.scale(innerDistance));
    }
    return currentPosition.copy();
  }
Пример #2
0
 private Vector2f getCurrentPosition() throws EndOfRoadException {
   if (this.arrivedAtEndOfEdge(lastKnownPosition)) {
     if (this.currentEdge.getDestinationNode().equals(this.destination)) {
       throw new EndOfRoadException();
     }
     Edge nextDestination =
         this.findNextDestination(currentEdge.getDestinationNode(), destination);
     if (nextDestination == null) {
       throw new EndOfRoadException();
     }
     this.setNextDestination(nextDestination);
     onRoadChange(nextDestination);
   }
   Vector2f direction =
       this.currentEdge.getDestinationNode().getPosition().sub(this.lastKnownPosition);
   direction.normalise();
   this.direction = direction.copy();
   direction.scale(this.getCurrentSpeed());
   return lastKnownPosition.copy().add(direction);
 }
Пример #3
0
 void update(Timer timer) {
   if (pathing) {
     distance = position.distance(target);
     float x = (target.getX() - position.getX());
     float y = (target.getY() - position.getY());
     float vx = speed * slf * (x / distance);
     float vy = speed * slf * (y / distance);
     velocity.set(vx, vy);
     scaledVelocity.set(vx * scale, vy * scale);
     if ((timer.getTick() % (timer.getTimerSetting().getSpeed() * 0.05f)) == 0) {
       Vector2f v = velocity.scale(0.05f);
       // Vector2f sv = velocity.scale(0.05f);
       if (distance < 1f) {
         position.set(target);
         setPosition(position.getX(), position.getY());
       } else {
         position.set(position.getX() + (v.getX() * scale), position.getY() + (v.getY() * scale));
         setPosition(position.getX(), position.getY());
       }
     }
   }
 }