title: libgdx - Rectangle collision, change velocity
body: <p>I am buidling a small 2d real-time-strategy ( RTS ) game with rectangle hitboxes.</p>
  
  <p>So I am able to detect the position of my object, target position of my object and to detect of the future position will be overlapping.</p>
  
  <p>But how can I calculated a smaller velocity (velocety * ( delta - X ) in order to sit right beside the "DamnBlock" ?</p>
  
  <pre><code>private Vector2 position;
  private Vector2 positionMoveTarget;
  private float width;
  private float height;
  private Rectangle DamnBlock; /* Hit detection test */
  
  /* CODE CODE CODE */ 
  
  if(this.getPositionMoveTarget() != null ){
          if(this.getPosition() == this.getPositionMoveTarget()){
              this.setPositionMoveTarget(null);
          } else {
              Vector2 tmpPosition = new Vector2(this.getPosition());
              Vector2 tmpPositionMoveTarget =  new Vector2(this.getPositionMoveTarget());             
              Vector2 velocity = new Vector2(tmpPositionMoveTarget).sub(tmpPosition).nor().scl(this.getMoveSpeed()*delta);
              Vector2 tmpPositionWithVelocety = new Vector2(tmpPosition).add(velocity);
              if(new Rectangle(tmpPositionWithVelocety.x, tmpPositionWithVelocety.y,this.getWidth(),this.getHeight()).overlaps(DamnBlock)){
  
              /* 
  Calculate the biggest possible "velocety * ( delta - X )", in order to sit directly next to DamnBlock.
  But how ? 
  */  
  
              } else {
                  if(tmpPosition.dst2(tmpPositionMoveTarget)&lt;tmpPosition.dst2(tmpPositionWithVelocety)){
                      this.setPosition(this.getPositionMoveTarget());
                      this.setPositionMoveTarget(null);
                  } else {
                      this.setPosition(tmpPositionWithVelocety);
                  }                   
              }               
          }
      }
  </code></pre>