# Jumping Script

**URL:** <https://forum.kirupa.com/t/jumping-script/221681>\
**Category:** flash\
**Created:** [April 6, 2007, 10:04am UTC](https://forum.kirupa.com/t/jumping-script/221681 "2007-04-06T10:04:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![FlashHed](https://avatars.discourse-cdn.com/v4/letter/f/e480ec/32.png) [@FlashHed](https://forum.kirupa.com/u/FlashHed)\
**Post date:** [April 6, 2007, 10:04am UTC](https://forum.kirupa.com/t/jumping-script/221681/1 "2007-04-06T10:04:31Z")

</div>

Hey everybody,

I wrote this script that allows you to jump from platform to platform and I am trying to think of a way to put a cap on the height that the player can jump. If you have any ideas let me know. If not play around with this script anyways.

For this to work you will need a movieclip on stage called ‘pc’ and your 3 platforms on the stage with instance names ‘platform0’, ‘platform1’, ‘platform2’. Put the registration points for the pc clip at the bottom, and for the platform clip at the top.

w,s,a,d are used instead of the arrow keys

var home = this;  
onEnterFrame = function () {  
platform\_jumping(pc, “platform”, 5, 20);  
};  
//  
function platform\_jumping(targ1, targ2, move\_speed, jump\_speed) {  
var move\_speed:Number;  
var falling:Boolean = true;  
var gravity:Number = 0;  
for (i=0; i\<4; i++) {  
obj = home[targ2+i];  
if (falling == true) {  
gravity = 10;  
} else if (falling == false) {  
gravity = 0;  
}  
if (targ1.hitTest(obj)) {  
falling = false;  
}  
}  
// Left  
if (Key.isDown(65) && targ1.\_x\>0) {  
targ1.\_x -= move\_speed;  
}  
// Right  
if (Key.isDown(68) && targ1.\_x\<Stage.width) {  
targ1.\_x += move\_speed;  
}  
// Up  
if (Key.isDown(87) && targ1.\_y\>0) {  
targ1.\_y -= jump\_speed;  
}  
targ1.\_y += gravity;  
updateAfterEvent();  
}  
//
