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();
}
//