Page 1 of 1
Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 3:43 pm
by ajtgarber
Not to sound like an idiot or anything but... how do you handle collisions on side scrollers? So far I've only had trouble when the level scrolled
but when it had no offsets it worked fine
. Right now the game is a 15x15 grid of 32x32 tiles, and I've tried about 10 ways in the past month
to get this to work and so far they've failed.
Ps. Sorry if I sound retarded, I'm just frustrated and tired
Re: Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 5:34 pm
by GroundUpEngine
If your doing collision e.g. player vs tile, then you will need to test the object against the player's position + the
offset
Something like this will work->
Code: Select all
bool Player::IsCollide(Tile tile, int offsetX, int offsetY)
{
// add the offsetx
_x = x + offsetX;
_y = y + offsetY;
if( (_x >= tile.x) && (_x <= tile.x + tile.w) && (_y >= tile.y) && (_y <= tile.y + tile.h) )
return true;
}
Re: Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 6:41 pm
by eatcomics
yeah it isn't easy to figure out how to help without some code, or an explanation of how you're doing things, but GUE's advice should help :D
In layman's terms: give us more info, so we can better help you...
Re: Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 8:06 pm
by ClassA
ajtgarber wrote:So far I've only had trouble when the level scrolled but when it had no offsets it worked fine
Generally, I will always store player position and calculate collisions using "world" coordinates (i.e. positions relative to the level). I store the "camera" position separately and use it as an offset to convert "world" to "screen" coordinates only when drawing. This means that scrolling has no effect on game logic/collision code.
Re: Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 8:19 pm
by Falco Girgis
ajtgarber wrote:Not to sound like an idiot or anything but... how do you handle collisions on side scrollers? So far I've only had trouble when the level scrolled
but when it had no offsets it worked fine
. Right now the game is a 15x15 grid of 32x32 tiles, and I've tried about 10 ways in the past month
to get this to work and so far they've failed.
Ps. Sorry if I sound retarded, I'm just frustrated and tired
It should be the exact same as with nonscrolling. The only "offsets" that scrolling is applying is only for RENDERING, not to the actual location of the entities. So I'm not exactly sure how you're handling it.
But like ClassA said, it shouldn't make any difference how things are "rendered."
Imagine if my collision checks changed when we zoomed in/out and rotated the world in ES.
Re: Collision Detection for side scrolling games
Posted: Wed Mar 17, 2010 8:37 pm
by GroundUpEngine
Soz ignore my post, I haven't got enough sleep recently
But ye only the tile rendering gets affected by the offsets, whereas the collision checks are normal just like non-scrollers.
Re: Collision Detection for side scrolling games
Posted: Thu Mar 18, 2010 5:31 pm
by ajtgarber
Thanks for the replies! I think I figured out how to get it working *crosses fingers*, thanks everyone! Falco, great work on LibGyro btw!