PDA

View Full Version : Collision Issue



Shneidr
April 28th, 2010, 11:22 PM
Hey guys,

So I'm programming this platform scrolling game, working really hard at fixing up a lot of nit picky issues and I've come across an issue with my ground collision: when the player jumps to a higher ledge that should be too high to get atop, as long as he's close the ground puts him at the top. This is starting to really frustrate me because I've done everything I can think of to remedy this.
Now, my collision mc's (the limits) are made up of 3 different mc's: the walls, the ground and the ceilling. I did this rather than create one limits mc so that the coding doesnt get confused.
Anyways, here's the collision and jumping code that I use:




// Ground Collision
for (i=1; i<=50; i++) {
if (jumpPower<=0) {
if (!ground.hitTest(hero._x+6, hero._y-i, true) && !ground.hitTest(hero._x-6, hero._y-i, true)) {
hero._y -= i-1;
break;
} else {
hero.gotoAndStop("idle");
jumping = false;
jumpPower = 0;
}
}
}
// Jumping Collision
if (Key.isDown(Key.UP) && !jumping) {
jumping = true;
jumpPower = 8;
hero.gotoAndStop("jumping");
}
}
if (jumping) {
jumpPower--;
if (jumpPower>=8) {
jumpPower = -8;
}
if (jumpPower<=-8) {
jumpPower = -8;
}
hero._y -= jumpPower;
}



If anyone has any advice, or collision methods, or anything useful that may potentially help solve my issue, I'd be exceedingly grateful.

PS, I have a visual example of my problem attatched.

Thanks!

PsychoA
May 4th, 2010, 12:22 PM
Now how come the good game has no newsletter?

snnd
May 5th, 2010, 05:25 AM
I had the same problem, while programming a javascript jump'n'run. I wrote the engine all by myself and faced exactly the same problem.

In my case the problem was, that the lower collision points of the player sprite, somehow slipped into the solid area (f.i. the wall it bounced against). So the engine decided, that "if bottom points are equal or lower than wallsprite, collide on top of the wall sprite. place player on to of the wall".

So without knowing exactly your whole code I suggest the problem to hide somewhere in here



if (!ground.hitTest(hero._x+6, hero._y-i, true) && !ground.hitTest(hero._x-6, hero._y-i, true)) {
// place player on top, if collision point hits or intersects with "ground"
hero._y -= i-1;
break;
}


So what's you job now? Figure how to avoid your character/points slip into solid level areas. Precalculate any step the character shall do, BEFORE placing the character.

These are just assumptions based on the given information. I'm sorry for not coming up with the right solution for you.