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?
Should I change how I do BG collision detection?
Moderator: Moderators
Forum rules
- For making cartridges of your Super NES games, see Reproduction.
-
- Posts: 3140
- Joined: Wed May 19, 2010 6:12 pm
- rainwarrior
- Posts: 8732
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Should I change how I do BG collision detection?
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:
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); }
-
- Posts: 3140
- Joined: Wed May 19, 2010 6:12 pm
Re: Should I change how I do BG collision detection?
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?
Re: Should I change how I do BG collision detection?
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.
-
- Posts: 3140
- Joined: Wed May 19, 2010 6:12 pm
Re: Should I change how I do BG collision detection?
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.