-
Platform Game Problem..HEP!!
Hi Guys,
I'm in the process of making my first flash platform game and im having problems with the guy landing on the platforms (he falls though them half of the time, espeicially if you go to the top of the screen and casually fall off one of the upper platforms he will fall through all platforms and land on the very bottom one)
here is the demo, use left right arrows and up arrow to jump): http://www.thekay.co.uk/platformtest.htm
Here is the code which is all on the first frame of the movie (i dont have any code on any movie clip (the platform movieclip is called 'land' and the man movieclip is called 'guy')
Basically i want the man to land accurately on all of the platforms without falling through them, can anybody point me in the right direction?
init();
function init(){
guy.dx = 0;
guy.dy = 0;
guy.jumping = false;
} // end init
guy.stop();
guy.onEnterFrame = function(){
//check keys
if(Key.isDown(Key.RIGHT)){
guy._xscale=-100;
guy._x +=6;
guy.play();
if (guy._x >550) {guy._x = 550;}
} else {guy.stop();}
if(Key.isDown(Key.LEFT)){
guy._xscale=+100;
guy._x -=6;
guy.play();
if (guy._x <40) {guy._x = 40;}
} // end if// end if
//jump
if(Key.isDown(Key.UP)){
if(guy.jumping == false){
guy.jumping = true;
guy._y -= 5;
guy.dy = -5;
} // end if jumping false
} // end if keydown
guy.dy += .5;
//guy hits ground
if (land.hitTest(guy._x, guy._y, true)){
guy.jumping = false;
} // end if land test = true
guy.dy = 0;
} // end if land hittest
guy._y += guy.dy;
} // end enterFrame
-
Im using Flash MX 2004 by the way.
-
Script kiddie
Just make the platforms thicker.
-
Making the platforms thicker is not what im after, i want the man to land on the platforms, not 'in' them.
-
Lurker at Heart
Thicker platforms is one solution, could you post the code you currently use for platform detection?
-
All code is in my first post but this is the bit i use for land detection:
//guy hits ground
if (land.hitTest(guy._x, guy._y, true)){
guy.jumping = false;
} // end if land test = true
guy.dy = 0;
} // end if land hittest
-
Lurker at Heart
Ah! So are the platforms all a part of the base land clip then? I misunderstood, I assumed they'd be individual items.
-
yes, all platforms are part of the same 'land' movieclip.
-
Lurker at Heart
Okay, I'd suggest moving them out and then doing a check of each platform, one by one. However, if you just want to make a small adjustment to the code you are using, try something like this:
Code:
//guy hits ground
for(yMod=0;yMod<=10;yMod++){
if (land.hitTest(guy._x, guy._y - yMod, true)){
guy.jumping = false;
} // end if land test = true
}
guy.dy = 0;
} // end if land hittest
What that will do is broaden the hit zone by about 10 pixels.
-
Truimagz.com
This is an old school art based platformer, I personally would do the coding alot differently and shorten it quite a bit, but it's a great start in showing you how to make art based platformers.
http://truimagz.com/Hosting/Art%20B...0Platformer.fla
here is the swf live
http://truimagz.com/Hosting/OS_bobble_v1.swf
-
Hi Everfornever
I try to download the .fla file you posted (right click - save target as) but it won't download (says site unavailable or cannot be found) Studying the bubble bobble game code could be just what i am after
Thanks for your help too egoAnt, i gave it a try and it seems to work ok but ideally an accurate land on a platform would be better.
-
Please, Call Me Bob
well im sure you know the problem quite well, the platforms are too small and your _y position flies right past 'em, you may need a different approach to your collision testing
an easy way to do this right is to use EgoAnt's idea, just make a platform mc and let your player cycle through all the hittests, here's an example:
ytemp=_y;
<movementactionshere>
ytemp2=_y;
for(i=0;i<_root.platformnum;i++){
if(ytemp>=_root["platform"+i]._y){
if(ytemp2<=_root["platform"+i]._y){
_y=_root["platform"+i]._y;
guy.jumping = false;
break;
}
}
}
if the number of platforms is unknown:
ytemp=_y;
<movementactionshere>
ytemp2=_y;
for(i=0;i<_root.platformnum;i++){
//this statement is used to find if the mc exists, there are many different ways to do it though
//and you may want to use one of those if you plan on using alpha, i think there's even one more straightforward
if(_root["platform"+i]._alpha!=100){
break;
}
//...................
if(ytemp>=_root["platform"+i]._y){
if(ytemp2<=_root["platform"+i]._y){
_y=_root["platform"+i]._y;
guy.jumping = false;
break;
}
}
}
if u have trouble understanding anything...just ask
prettymuch this just checks to see if your mc has moved down through a platform, and sets your _y accordingly
-
Truimagz.com
-
That link works cheers everfornever.
Cheers all for the info and help, between you all i've pretty much got my platform problems covered, you are all stars!! )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|