title: Java libgdx: limiting circular velocity (swinging entity)
body: <p>I am currently working on a 2D side scroller and have implemented the techniques use in <a href="http://gamedevelopment.tutsplus.com/tutorials/swinging-physics-for-player-movement-as-seen-in-spider-man-2-and-energy-hook--gamedev-8782" rel="nofollow">this</a> article for a grapple hook, and it works really well. My problem is I want my player to be able to swing around the rope a little bit to gain a bit of momentum, but currently I can't stop the player from moving all the way up to 90 degrees either side. What techniques can be applied to force this limit? </p>
  
  <p>I have tried using a separate player speed for swinging but this only slows the process down I can still swing up to 90 deg each side.</p>
  
  <p>Here's my update function in the player</p>
  
  <pre><code>public void update(float dt){
      //handle friction and air resistance
      if(dx !=0){
          if(touchingGround) {
              // apply friction
              if (dx &gt; 0) {
                  dx -= retardation;
              } else {
                  dx += retardation;
              }
          } else {
              //applied air resistance
              if (dx &gt; 0) {
                  dx -= airResistance;
              } else {
                  dx += airResistance;
              }
          }
      }
      // handle gravity
      dy -= Constants.GRAVITY * dt;
      if(dy &lt; -terminalVelocity){
          dy = -terminalVelocity;
      }
  
      /*
          Handle Player movement
       */
  
      if(right){
          if(dx &lt;= maxSpeed){
              dx += acceleration;
          }
          dx = maxSpeed;
      }
  
      if(left){
          if(dx &lt;= -maxSpeed){
              dx -= acceleration;
          }
          dx = -maxSpeed;
      }
  
      if(isGrappling){
  
          //If we collide with something we need to stop grappling
          if(hasCollided){
              isGrappling = false;
          } else {
  
              //  This algorithm from here:
              // http://gamedev.stackexchange.com/questions/61596/player-rope-swing
  
              float currentD = (float) Math.sqrt(((grappleX - x) * (grappleX - x)) + ((grappleY - y) * (grappleY - y)));
              float prevX = getX(), prevY = getY();
  
              if (currentD &gt; grappleRadius) {
                  Vector2 hookPos = new Vector2(grappleX, grappleY);
                  Vector2 testPos = (new Vector2(x, y).sub(hookPos)).nor();
  
                  y = (hookPos.y + testPos.y * grappleRadius);
                  x = (hookPos.x + testPos.x * grappleRadius);
  
                  // s = d / t
                  dx += (x - prevX) / dt;
                  dy += (y - prevY) / dt;
              }
          }
      }
  
      /*
          Collision Detection, handle last always!
       */
  
      float oldX = getX(), oldY = getY();
      boolean collisionX = false, collisionY = false;
  
      // move on x
      x += dx * dt;
  
      // calculate the increment for step in #collidesLeft() and #collidesRight()
      increment = collisionLayer.getTileWidth();
      increment = getWidth() &lt; increment ? getWidth() / 2 : increment / 2;
  
      if(dx &lt; 0) // going left
          collisionX = collidesLeft();
      else if(dx &gt; 0) // going right
          collisionX = collidesRight();
  
      // react to x collision
      if(collisionX) {
          setX(oldX);
          dx = 0;
      }
  
      // move on y
      y += dy * dt;
  
      // calculate the increment for step in #collidesBottom() and #collidesTop()
      increment = collisionLayer.getTileHeight();
      increment = getHeight() &lt; increment ? getHeight() / 2 : increment / 2;
  
      if(dy &lt; 0) {
          touchingGround = collisionY = collidesBottom();
          // we can only jump 2 times before we have to touch the floor again
          if(collisionY){
              numberOfJumps = 2;
          }
      } else if(dy &gt; 0) {
          collisionY = collidesTop();
      }
  
      // react to y collision
      if(collisionY) {
          setY(oldY);
          dy = 0;
      }
  
      hasCollided = collisionX || collisionY;
  }
  </code></pre>