title: jQuery game character movement system
body: <p>This is the code:</p>
  
  <pre><code>$(document).ready(function(){
  
          var mUp=false;
          var mLeft=false;
          var mRight=false;
  
          function movement(){
              $(function(){
                  if(mUp){
                      $('.user').animate({
                          bottom: '+=120'
                      },{
                          duration: 50,
                          easing: 'linear',
                          complete: function() {
                              $('.user').animate({
                                  bottom: '-=120'
                              },{
                                  duration: 150,
                                  easing: 'linear',
                                  complete: function() {
                                      mUp=false;
                                      if(!mRight&amp;&amp;!mLeft){
                                          $('.user').stop();
                                      }
                                  }
                              }).dequeue();
                          }
                      }).dequeue();
                  }
  
                  if(mRight){
                      $('.user').animate({
                          left: '+=1000'
                      },{
                          duration: 1000,
                          easing: 'linear',
                      }).dequeue();
                  }
  
                  if(mLeft){
                      $('.user').animate({
                          left: '-=1000'
                      },{
                          duration: 1000,
                          easing: 'linear',
                      }).dequeue();
                  }
              });
          }
  
  
  
          $(document).keydown(function(e){
              var curKey=e.keyCode;
              if(curKey==39){
                  console.log('right+');
                  if(!mRight){
                      mRight=true;
                      movement();
                  }
              }
              if(curKey==37){
                  if(!mLeft){
                      mLeft=true;
                      movement();
                  }
              }
              if(curKey==38){
                  console.log('up+');
                  if(!mUp){
                      mUp=true;
                      movement();
                  }
              }
          });
  
          $(document).keyup(function(e){
              var curKey=e.keyCode;
              if(curKey==39){
                  console.log('right-');
                  if(!mUp){
                      $('.user').stop();
                  }
                  mRight=false;
              }
              if(curKey==37){
                  console.log('left-');
                  if(!mUp){
                      $('.user').stop();
                  }
                  mLeft=false;
              }
              if(curKey==38){
                  console.log('up-');
              }
          });
      });
  </code></pre>
  
  <p>I'm working on a simple movement system for a jQuery based game. I can move the character left or right and jump. My problem begins when trying to move the character left or right while the jump animation is still in progress. If I jump while already moving left or right everything works fine but when I first jump then, while the jump animation is still in effect, try to move left or right it kinda goes crazy.</p>
  
  <p>JSFIDDLE: <a href="http://jsfiddle.net/2L86bdw0/" rel="nofollow">CLICK</a></p>