This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Collision with multijointed sprites

Collision with multijointed sprites
by on (#174385)
The way I calculate collision with multijointed sprites is by recalculating the x and y velocity of a joint, and then jump to the same routine as the player and enemies use. If collision occurs, then it bumps up the main object by the same amount.

I want to know if there's a more intuitive way of doing this, that doesn't involve recalculating velocities.
Re: Collision with multijointed sprites
by on (#174389)
Why would you ever look at velocities when doing collision checks? Are you putting the entire object in one large hit box, or is there one for every joint?
Re: Collision with multijointed sprites
by on (#174393)
So when a character jumps on a platform they don't pop up from underneath.
Re: Collision with multijointed sprites
by on (#174396)
psycopathicteen wrote:
So when a character jumps on a platform they don't pop up from underneath.

I'm confused. What would make this happen? Perhaps I'm misunderstanding what you mean by popping up from underneath.
Re: Collision with multijointed sprites
by on (#174399)
If there is a platform you can jump through, you'd end up snapping to the platform if you get close to it.
Re: Collision with multijointed sprites
by on (#174400)
Can't you simply not do the snapping is this case? Snap only when the object is already "grounded", so that it runs along the ground, or when it's in the air but moving down, so it can only land on the ground from above.
Re: Collision with multijointed sprites
by on (#174401)
psycopathicteen wrote:
If there is a platform you can jump through, you'd end up snapping to the platform if you get close to it.


I see. Yes, in this case checking that dY > 0 is important.
Re: Collision with multijointed sprites
by on (#174402)
...and if the character was above the platform before he landed.

I guess this isn't important for multijointed sprites.
Re: Collision with multijointed sprites
by on (#174403)
Wait, is this for collisions between multijointed sprites and the level map? That could be very complicated, depending on what the extra pieces are... if they're legs, the object should be able to step on higher ground with one foot without moving all the other parts up. I honestly have no idea how I'd animate something like that properly.
Re: Collision with multijointed sprites
by on (#174405)
psycopathicteen wrote:
If there is a platform you can jump through, you'd end up snapping to the platform if you get close to it.

Haunted: Halloween '85 uses soft snapping. If Donny's bottom center point is less than 8 pixels below the top of a platform, his velocity is set slightly upward until he's aligned with the platform. This means hills can be stored as stairs in the level's collision map, giving the illusion of actual slope support.* It also means a 66 pixel vertical leap can put him on a platform 72 pixels above the ground.


* Until you try to jump off a downhill, which I admit is broken in that game.
Re: Collision with multijointed sprites
by on (#174412)
tepples wrote:
* Until you try to jump off a downhill, which I admit is broken in that game.

You can solve this by adding a grace period; when grounded, set a counter. When airborn, decrease the counter if it is greater than zero. Jumping is then allowed if the counter is nonzero.

Donkey Kong Country has an absurdly high period of time where, when the player has transitioned from being grounded to airborn, the player may still perform a jump. I'm not sure this grace period ever expires in DKC, though I haven't experimented with it enough. Level design should be done with this kind of thing in mind (like much of DKC is), but it's an adequate solution to prevent a "why won't he/she jump?!" situation when going downhill. Battletoads has this problem if the player dashes down a hill. A normal-paced walk is fine, though.

In one of my games, I have a grace period of 10 frames, and there is a visual indication of a sweat drop to the side of the player.
Re: Collision with multijointed sprites
by on (#174415)
Wait, you mean sliding a sprite up to the platform was a well known trick? I never even heard of it until this thread.
Re: Collision with multijointed sprites
by on (#174458)
tepples wrote:
Haunted: Halloween '85 uses soft snapping. If Donny's bottom center point is less than 8 pixels below the top of a platform, his velocity is set slightly upward until he's aligned with the platform. This means hills can be stored as stairs in the level's collision map, giving the illusion of actual slope support.* It also means a 66 pixel vertical leap can put him on a platform 72 pixels above the ground.

* Until you try to jump off a downhill, which I admit is broken in that game.


I had actually described this slant trick to Nova, quite some time ago, when explaining the benefits of using 8-point collision for optimization.

There's actually an easy way to fix that downhill bug, I forget the particulars though? I'd need to look through some old coding notes.
Re: Collision with multijointed sprites
by on (#174461)
By checking several pixels lower when on ground?