title: Action Script 3. Make character jumping correctly and add collision with objects
body: <p>I'm creating simple flash game. 
  Idea: Green character walking on the ground by clicking (left/right arrows) when click space button character must jump. For now character stay on the ground, walking, but don't have collision with wall(going through the wall).
  In this part of code I tried to make collision with ground3 wall, but It not working, character going through the wall, and if I jump on the ground3 (staying on the top) I can't move to right, because It touching ground3. I need to make that if character touch with right side the wall then set speed to 0.</p>
  
  <p>Here is part of code (move right):</p>
  
  <pre><code> if(right){
  
              Hero.x_speed = walkspeed;
              setDirection(0);
              trace("right");
  
  /////////////////////SOMETHING WRONG HERE//////////////////////////////
              if (ground3.hitTestPoint((centrasXright), centrasY, true)){
                  trace("HIT THE WALL/GROUND with RIGHT"); //always get this message when stay on the ground 3
                  Hero.x_speed = 0;
              }
              else {
                  trace("Do not touch anything");
  
              }
  </code></pre>
  
  <p>Here is photo of my game:
  <img src="https://i.stack.imgur.com/CdF01.png" alt="game"></p>
  
  <p>Here are my variables:</p>
  
  <pre><code>private var gravity:Number = 0.01;
  private const max_speed:int = 8;
  
  private const walkspeed:int = 4;
  private const jumpspeed:int = 10;
  
  private const start_x:int = 50;
  private const start_y:int = 300;
  
  private var left:Boolean;
  private var up:Boolean;
  private var right:Boolean;
  private var space:Boolean;
  
  private var ground:Ground = new Ground;
  private var Hero:hero = new hero;
  </code></pre>
  
  <p>Here is part of my code:</p>
  
  <pre><code>private function create_hero(){
              addChild(Hero);
              Hero.x = start_x;
              Hero.y = ground.y-30;
              Hero.x_speed = 0;
              Hero.y_speed = 0;
  
  
          }
          private function setDirection(param) {
      if (param == 0) {
          Hero.scaleX = 1;
      } else {
          Hero.scaleX = -1;
      }
  }
  
          private function update_hero(){
              Hero.y_speed += gravity;
  
              if(left){
                  Hero.x_speed = -walkspeed;
                  setDirection(1);
              }
                  var test:MovieClip = new MovieClip;
                  test.x = Hero.x;
                  test.y = Hero.y;
                  var centrasXright:Number = test.x + (Hero.width/2);
                  var centrasXleft:Number = test.x - (Hero.width/2);
                  var centrasY:Number = test.y + (Hero.height/2);
              if(right){
  
                  Hero.x_speed = walkspeed;
                  setDirection(0);
                  trace("right");
  
                  if (ground3.hitTestPoint((centrasXright), centrasY, true)){
                      trace("HIT THE WALL/GROUND with RIGHT");
                      Hero.x_speed = 0;
                  }
                  else {
                      trace("Do not touch anything");
  
                  }
  
  
              }
              if(up &amp;&amp; Hero_col.can_jump){
                  Hero.y_speed = -jumpspeed;
  
  
              }
  
              if(Hero.y_speed &gt; max_speed){
                  Hero.y_speed = max_speed;
              }
              ///////////////////////////////////////////////////////////////////
              ////////////////HERE IS COLLISION WITH THE TOP OF GROUND///////////
                          ///////////////////////////////////////////////////////////////////
              if(Hero.y_speed&gt;0 &amp;&amp; Hero.hitTestObject(ground) || Hero.hitTestObject(ground3) ){
                          Hero.y_speed=0;
  
                  if(space){
                  trace("Clicked SPACE");
                  Hero.y_speed += gravity;
                  Hero.y -= 80;
                  }
                  else {
  
                  }
  
  
   }
  
              forecast_y = Hero.y + Hero.y_speed;
              forecast_x = Hero.x + Hero.x_speed;
  
              Hero_col.solve_all(forecast_x, forecast_y);
  
  
              Hero.x_speed = 0;
          }
  </code></pre>