Hi There,
Im creating a small platform game but i dont know how to get my character to land and stick to the platforms that fly by.
I have made the platform come from the right and move to the left and my character to can jump by i dont know how to code the hittest so that when he lands on the platform he stays on there and stays at the same rate aws the platform.
my heros actions script is this...
Code:
onClipEvent (load) {
characterSpeed = 3;
//Where the character start jumping from
y_start = _y;
//On load, jumping is false
jumping = false;
//And jumpspeed is 0
jumpspeed = 0;
}
onClipEvent (enterFrame) {
//If jumping is true
if (jumping) {
//The _y + jumpspeed = _y
_y += jumpspeed;
//And here is the gravity which makes the character fall
jumpspeed += .8;
//But if the characters's _Y > than the y_start
if (_y>=y_start) {
// The characters's Y = y_start
_y = y_start;
//And jumping is false
jumping = false;
}
}
//Else
else {
//If the SPACE Key is down
if (Key.isDown(Key.UP)) {
//Jumping becomes true
jumping = true;
//And jumpspeed is -14
jumpspeed = -10;
// playjumping animation
this.gotoAndPlay("jump");
} else {
if (Key.isDown(Key.DOWN)) {
this.gotoAndPlay("crouch");
}
}
}
if (Key.isDown(Key.RIGHT)) {
this._x += characterSpeed;
} else if (Key.isDown(Key.LEFT)) {
this._x -= characterSpeed;
}
}
and here is the code on the platform...
Code:
onClipEvent (load) {
moveSpeed = -5;
this._x = 550;
this._y = 245;
}
onClipEvent (enterFrame) {
this._x += moveSpeed;
//if this goes off the edge of the screen, move back to the start
if (this._x <=-100) {
this._x =550
}
}
Any help would be amazingly appreciated. Thankyou
Tim