A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to climb a ladder?

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    3

    How to climb a ladder?

    How can I make it so that my character climbs a ladder whilst holding the down button? I attached a sample of my project for someone to help me with

    Thanks in advanced

    code:

    onClipEvent (load) {
    var ground:MovieClip = _root.ground;
    var grav:Number = 0;
    var gravity:Number = 2;
    var speed:Number = 7;
    var maxJump:Number = -12;
    var touchingGround:Boolean = false;

    }
    onClipEvent (enterFrame) {
    _y += grav;
    grav += gravity;
    while (ground.hitTest(_x, _y, true)) {
    _y -= gravity;
    grav = 0;
    }
    if (ground.hitTest(_x, _y+5, true)) {
    touchingGround = true;

    } else {
    touchingGround = false;

    }
    if (Key.isDown(Key.RIGHT)) {
    _x += speed;
    }
    if (Key.isDown(Key.LEFT)) {
    _x -= speed;
    }
    if (Key.isDown(Key.UP) && touchingGround) {
    grav = maxJump;
    }
    if (Key.isDown(Key.DOWN)) {
    if(ladder.hitTest(this)){
    grav = 0;
    _x += speed;

    }
    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;
    }
    }
    }
    Attached Files Attached Files
    Last edited by theherotom; 08-01-2011 at 08:24 AM.

  2. #2
    Member
    Join Date
    Jul 2011
    Location
    United States
    Posts
    37
    Well create a movie clip of a ladder and make it when your character hits that movie clip to turn the gravity off. and use
    Actionscript Code:
    if(Key.isDown(Key.DOWN)) {
    _y += speed;
    }
    to descend down the ladder.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    That's exactly what it is like atm... doesn't work.

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