super mario jump-on-head killing

Started by
8 comments, last by no_skill 20 years, 2 months ago
hy, i''m looking for a technique for solving super mario like collision detection (killing by jumping on an object). i''ve already tried to implement it, but my approach has some flaws. do you know some tutorials about this, or a piece of code to look at? thanks in advance, no_skill
Advertisement
Assuming -Y is down, +Y is up...

You want the player horizontally above the object...

((PLAYERX + PLAYERWIDTH) > ENEMYX) && (PLAYERX < (ENEMYX + ENEMYWIDTH))

... you want the player coming downwards only...

(PLAYERVEL_Y <= 0)

... and you want the player''s "feet" above a certain "head" margin...

((PLAYERY + PLAYERHEIGHT) > (ENEMYY + HEADTHICKNESS))

Logical AND all those together, and you''ve got yourself a "head-hit" collision test. If that fails, but the player is still colliding with the enemy, handle it like otherwise (usually injure or kill the player).

Mind you, re-write it first. I just jotted some psuedocode so I know exactly what I''m talking about.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
implementing that is no problem, but i''m having two moving objects and if the player is moving down and the enemy up sometimes i miss the collision.

i tested the whole path the player traveled so far against the enemy''s new position, but the problem still occurs (of course not as often as before).

i''ll try testing the two full paths against, but i wonder how it was done on the snes etc. i don''t think it has enough power for such calculations.

(...maybe it had, as it''s only a if with different parameters....)
Since we know that Mario must always be on top of a monster for a head on collision, why not make the first test vertical. That is:

If Mario.Y > Monster.Y, then check if (Mario.Y - Monster.Y) = 1 (or however maximum distance for an actual kill).

Then, check simply if he is within horizontal bounds:

If (abs(Monster.X - Mario.X) < Mario.Width)) then go run the monster dead routine. abs() means absolute function.

I think this is how I implemented top-down collision technique in my game. Tell me if I''m wrong.
I luv mah bubble tea.
but what if mario moves through this area in one frame?

that''s the main problem.


how do games in general handle collision detection between two moving objects?

do they compare only the end position of both movements.

or test the whole path of one object against the end position of another.

how?
I dont know why you have problems...
if they move more then 1000 pixels per second then you may have this problem, but there is no problem doing something like this:

if (player.x+player.w > enemy.x) && (player.x<enemy.x+enemy.w) && (player.h+player.y-enemy.y<=0)enemy.dead=true;


[edited by - ilankt on January 27, 2004 2:15:16 AM]
How appropriate, you fight like a cow!
thanks, i'll try that (along with a lot of ideas i got in the meantime )

i'm wondering how games in general deal with collision detection with two moving objects

a)
1. test every object against the map -> new position
2. only compare the new positions of each object against each other

b)
1. test the whole movement of every object against the whole movement of each other object + the map

c)
i don't know


how do games solve this nowadays?

[edited by - no_skill on January 27, 2004 6:18:54 AM]
Dont use a single point x,y for checking, or you could pass up the collision.

Use bounding boxes x1,y1 x2,y2 that way you have a larger area to hit in.

If your running at 30 frames per second, like most games do, then there is no way you should pass up any collisions.

if you have bounding rectangles, make rays from each corner from where the object started to where it ended for both objects, see if any of the rays intersect the other objects rays. Sounds good to me.
thanks for your suggestions.

i''ve already solved the problem by using bounding boxes.

i''ll put the code on jnrdev when it''s complete.


http://jnrdev.weed-crew.net

This topic is closed to new replies.

Advertisement