I am making a platform game where its the side view. When i do it the character never stays on the top of the platform, he sinks in it a bit. here is the script on the character: onClipEvent (load) { speed = 3; gravity = 7; jumping = false; jump = 0; fall = false; } onClipEvent (enterFrame) { if (!_root.platform.hitTest(this._x, this._y, true) && !jumping) { _y += gravity; } if (_root.platform.hitTest(this._x, this._y, true) && falling) { jump = 8; falling = false; jumping = false; } } onClipEvent (enterFrame) { if (Key.isDown(65)) { _x -= speed; gotoAndStop(2); _xscale = -100; } else if (Key.isDown(68)) { _x += speed; gotoAndStop(2); _xscale = 100; } else { gotoAndStop(1); } if (Key.isDown(87) && jumping == false) { jumping = true; } if (jumping) { this._y -= jump; jump -= .5; if(jump<0) { falling = true; } if(jump <-10){ jump =-10; } } }
since the guy has a y velocity, he isn't just moving...he's skipping down at that rate. So, when he hits the platform, you tell him to stop, but he has still skipped, so he isn't perfectly on top...maybe 3 pixels on or something. Anyway, add code that says that if he is on one, position him on top.
This is assuming that the guy's center is at his feet and the platform's is at it's top-left corner. The else is just more powerful coding I added to help.
Btw, great to see another AS2 programmer! But, I'm soon going to make the jump to 3...<sigh>.
sorry, I should have said "_root.platform._y + 1". That way, it's guaranteed to be overlapping the platform so the hitTest will come false and it won't fall again.
onClipEvent (enterFrame) { if (this._x>=434) { //this is customizable to fit screen this._x = 430; } if (this._x<=142) { //this is customizable to fit screen this._x = 145; } }