A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: charackter running mid air

  1. #1
    Junior Member
    Join Date
    Nov 2015
    Posts
    6

    charackter running mid air

    How do I fix running iin mid air
    so when i jump it plays the normal jump animation and when I press right in mid air my char tries to walk and i want to disable that
    How do I do that?

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    I would do the sdame as you have for touching ground, create another boolean var, maybe
    var jumping:Boolean = false; inisde the onLoad like the others.

    When in mid air set jumping to true, then inside your left and right code usesomething like so

    PHP Code:
    if (Key.isDown(Key.RIGHT))
    {
        
    _xscale = +scale;
        
    _x += speed;
        if (!
    jumping)
        {
            
    this.gotoAndStop(2);
        }

    then when character is back on ground set jumping = false

    good luck

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    HI,

    Using the code you already are using, try something like so
    PHP Code:
    onClipEvent (load) {
        var 
    ground:MovieClip _root.ground;
        var 
    grav:Number 0;
        var 
    gravity:Number 2;
        var 
    speed:Number 7;
        var 
    maxJump:Number = -30;
        var 
    touchingGround:Boolean false;
        var 
    jumping:Boolean false;
        
    scale _xscale;
    }
    onClipEvent (enterFrame) {
        
    _y += grav;
        
    grav += gravity;
        while (
    ground.hitTest(_x_ytrue))
        {
            
    _y -= gravity;
            
    grav 0;
        }
        if (
    ground.hitTest(_x_y 5true))
        {
            
    jumping false;
            
    touchingGround true;
        }
        else
        {
            
    jumping true;
            
    touchingGround false;
        }
        if (
    Key.isDown(Key.RIGHT))
        {
            
    _xscale = +scale;
            
    _x += speed;
            if (!
    jumping)
            {
                
    this.gotoAndStop(2);
            }
        }
        if (
    Key.isDown(Key.LEFT))
        {
            
    _xscale = -scale;
            
    _x -= speed;
            if (!
    jumping)
            {
                
    this.gotoAndStop(2);
            }
        }
        if (
    Key.isDown(Key.UP) && touchingGround)
        {
            
    grav maxJump;
            
    jumping true;
            
    this.gotoAndStop(3);
        }
        if (
    Key.isDown(Key.DOWN))
        {
            
    this.gotoAndStop(4);
        }
        if (
    ground.hitTest(_x + (_width 2), _y - (_height 2), true))
        {
            
    _x -= speed;
        }
        if (
    ground.hitTest(_x - (_width 2), _y - (_height 2), true))
        {
            
    _x += speed;
        }
        if (
    ground.hitTest(_x_y - (height), true))
        {
            
    grav 3;
        }
    }

    onClipEvent (keyUp) {
        
    this.gotoAndStop(1);


  4. #4
    Junior Member
    Join Date
    Nov 2015
    Posts
    6
    thanks dude too kind

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center