PDA

View Full Version : platform irregular hittest



Mr.Pancake
April 17th, 2009, 05:47 PM
Im making a platformer, the hittest for the floor needs to be moer advanced so i can add more graphics to the ground movieclip instead of making sepperate movieclips with sepperate instances.

i saw a piece of code somewhere that uses FOR loop. isn't there a simpler code to make irregular hittest?

here's my actionscript and file:


jump = 0;
grav = 1;
gravspeed = 1;
onEnterFrame = function () {
//set gravity on
if (_root.grav == 1) {
gravspeed = gravspeed*1.2;
_root.player._y += gravspeed;
}
//clear gravity if player hits ground
if (_root.player.hitTest(_root.g)) {
gravspeed = 1;
jumpheight = 1;
jump = 0;
grav = 0;
} else {
grav = 1;
}
//move right
if (Key.isDown(Key.RIGHT)) {
_root.g._x -= 5;
}
//move left
if (Key.isDown(Key.LEFT)) {
_root.g._x += 5;
}
//set jump
if (Key.isDown(Key.SPACE)) {
_root.jump = 1;
_root.grav = 1;
}
//jump motion
if (_root.jump == 1) {
_root.player._y -= 20;
gravspeed = gravspeed*1.1;
_root.player._y += gravspeed;
}
//set max gravity
if (gravspeed>=15) {
gravspeed = 15;
}
};


file: http://www.glennhofman.nl/gammetsest.fla

thanks in advance

Mr.Pancake
April 20th, 2009, 06:48 AM
anyone?

dandylion13
April 20th, 2009, 11:26 AM
Could you please explain this in a bit more detail?

"Im making a platformer, the hittest for the floor needs to be moer advanced so i can add more graphics to the ground movieclip instead of making sepperate movieclips with sepperate instances."

flashmxboy
April 20th, 2009, 11:52 AM
Do you think of sloped surfaces?

If so i have somehow solved it in this thread http://kirupa.com/forum/showthread.php?t=321521&page=3

WhiskeyShot
May 28th, 2009, 07:43 PM
Im making a platformer, the hittest for the floor needs to be moer advanced so i can add more graphics to the ground movieclip instead of making sepperate movieclips with sepperate instances.

i saw a piece of code somewhere that uses FOR loop. isn't there a simpler code to make irregular hittest?

here's my actionscript and file:


jump = 0;
grav = 1;
gravspeed = 1;
onEnterFrame = function () {
//set gravity on
if (_root.grav == 1) {
gravspeed = gravspeed*1.2;
_root.player._y += gravspeed;
}
//clear gravity if player hits ground
if (_root.player.hitTest(_root.g)) {
gravspeed = 1;
jumpheight = 1;
jump = 0;
grav = 0;
} else {
grav = 1;
}
//move right
if (Key.isDown(Key.RIGHT)) {
_root.g._x -= 5;
}
//move left
if (Key.isDown(Key.LEFT)) {
_root.g._x += 5;
}
//set jump
if (Key.isDown(Key.SPACE)) {
_root.jump = 1;
_root.grav = 1;
}
//jump motion
if (_root.jump == 1) {
_root.player._y -= 20;
gravspeed = gravspeed*1.1;
_root.player._y += gravspeed;
}
//set max gravity
if (gravspeed>=15) {
gravspeed = 15;
}
};
file: http://www.glennhofman.nl/gammetsest.fla

thanks in advance


ya a "for loop" doesn't make hittests for irregular shaped platforms, if that's what ur asking for, but it can let you use only a few lines of code to test for even hundreds of platforms(objects).

put this into your character movie clip:

onClipEvent (load) {; //things at start of movie
platforms = 40; //or how ever many(called anything, just a name ul remember)
}
onClipEvent (enterFrame) {; //this happens for every frame(lots)
for(i=0;i<platforms;i++){ //i is another variable, it starts as zero, and as long as its less than platforms it will add 1 every frame (i++)
if (this.hitTest(_root[ground+1])) {; //each piece of ground is named "ground1", "ground2", and so on. The i is increased by 1 every time, so it will check everything from ground1 to ground 40 in this case to be hittested
gravspeed = 1;
jumpheight = 1;
jump = 0;
grav = 0; //what you had up there
}
} //finishing or adding more watever


email me if yu hav more questions

TOdorus
May 29th, 2009, 08:28 AM
To offer an alternative, you might also check out bitmapbased collision detection