Should I change how I do BG collision detection?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Should I change how I do BG collision detection?

Post by psycopathicteen »

So far I've done it where the BG collision routine itself moves the sprites because it needed to know which where the sprites are comming from.

Because of this, everything that uses BG collision has to be controlled by it's velocity. For certain types of sprites this works out nicely, but for other types (such as rotating joints) it ends up making the code into an unreadable mess.

I think it would make sense if I saved the coordinates before I move them, and jumped to the collision routine after moving it. Is this how other's do it?
User avatar
rainwarrior
Posts: 8731
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Should I change how I do BG collision detection?

Post by rainwarrior »

I do movement collisions with 2 pieces of input data, 1. an X/Y point, 2. the direction of motion. The collision result returns how many pixels to move the point back (opposite of motion direction) to escape collision, 0 if no collision.

Something like this:

Code: Select all

x = x + velocity_x;
if (velocity_x > 0) { x -= collide_tile_right(x,y); }
if (velocity_x < 0) { x += collide_tile_left(x,y); }

y = y + velocity_y;
if (velocity_y > 0) { y -= collide_tile_down(x,y); }
if (velocity_y < 0) { y += collide_tile_up(x,y); }
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Should I change how I do BG collision detection?

Post by psycopathicteen »

For pass-through tiles, do you just have the character snap to the platform if it's close to it, when moving downward, or do you do it the trickier way and actually detect if it was previously above it?
tepples
Posts: 22705
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Should I change how I do BG collision detection?

Post by tepples »

The walker movement code in The Curse of Possum Hollow tests whether a walker is in the top 8 pixels of a pass-through platform and with a downward velocity. If so, it zeroes the velocity and moves the walker upward. Dropping through a platform is done by ignoring pass-through platforms for a quarter second.
psycopathicteen
Posts: 3140
Joined: Wed May 19, 2010 6:12 pm

Re: Should I change how I do BG collision detection?

Post by psycopathicteen »

Got done rearranging the collision detection so now I can move sprites in any way that is convenient, just as long as I save the old coordinates before moving the sprite.
Post Reply