GLBasic forum

Main forum => GLBasic - en => Topic started by: Widget101 on 2021-May-08

Title: Not wanting pixel perfect collision
Post by: Widget101 on 2021-May-08
Hi,

I've drafted out a retro platformer (basically manic miner) and have an animated player but I'm finding that the pixel perfect collision is causing problems when my character walks off a wall. As he gets to the end of the wall he falls down as expected. However, as his arm extends back beyond his feet, the arm collides with the wall and the character sticks.

If I place a rectangular box under the sprite and use that for the collision then I don't get this problem as the edges of the collision check are always uniform (i.e. nothing sticking out past the edge to catch the wall).

Is there a way to replace the pixel perfect collision with a bounding collision instead? Or to make my rectangular box invisible so that it can't be seen but still detects collision.

Hopefully I've explained this clearly!! :S

Many thanks,

Steve.
Title: Re: Not wanting pixel perfect collision
Post by: Qedo on 2021-May-08
if I didn't get it wrong, I'd do this:
I would place the rectangle on the player without DRAWRECT and check the collision with BOXCOLL
Ad maiora
Title: Re: Not wanting pixel perfect collision
Post by: Widget101 on 2021-May-08
Thanks for the reply Qedo,

I was thinking about BOXCOLL but didn't think I'd be able to check its collision with a sprite or anim.

I think I've sorted it! Keep using the box sprite for the collision, but not actually drawing it to the screen seems to work!



Title: Re: Not wanting pixel perfect collision
Post by: Moru on 2021-May-17
You could also use the array for the map data instead of the sprite/box collision. Just convert the screen coordinates of your player and compare to the map data to decide of there is a collision or not. This should also have the added benefit of being pretty fast compared to sprite collision tests.

Example of what I mean:

https://www.gamedev.net/forums/topic/592791-index-to-2d-coordinates/
Title: Re: Not wanting pixel perfect collision
Post by: MrPlow on 2021-May-17
That manic miner looks really nice btw :)
Title: Re: Not wanting pixel perfect collision
Post by: StevetS on 2021-May-23
Quote from: Moru on 2021-May-17
You could also use the array for the map data instead of the sprite/box collision. Just convert the screen coordinates of your player and compare to the map data to decide of there is a collision or not. This should also have the added benefit of being pretty fast compared to sprite collision tests.

Example of what I mean:

https://www.gamedev.net/forums/topic/592791-index-to-2d-coordinates/

Ah! Never thought of that!  Checking against the object type in the array would be a really simple check as all objects of a certain type are grouped together ranges.   :booze:
Title: Re: Not wanting pixel perfect collision
Post by: erico on 2021-May-24
On Burger Lord I check a single player coordinate against the platform array, just like MORU said.
In fact it is very similar to boxcoll but I prefer doing it by hand and in my case it is actually a "line" collision as I donĀ“t need the height of box to collide.

Here is the game I have this system running:
https://sites.google.com/view/fuedhq/burger-lord?authuser=0
Title: Re: Not wanting pixel perfect collision
Post by: dreamerman on 2021-Oct-21
As already mentioned by others, I would use simple array check for map tiles as those are mostly square sized, and rect colisions for all other game objects like enemies/bullets/powerups, pixel perfect collision sound nice but as you already noticed isn't perfect for all situations :) and it's much slower if you will have dozens sprites to check. Depending on game can be using several smaller rect boxes for collision that would cover most of player sprite, let's say you have top down shooter, you can easilly use two rect for palyer aircraft, one for hull second for wings and that's it.

Just answering if anyone would search for similar topic.
Title: Re: Not wanting pixel perfect collision
Post by: spacefractal on 2021-Oct-24
alternative uses some pixels around the image. im think im used multiple boxcol collosions on my games. Only in Karma Miwa im used pixel collection by the floor by using a second imagemap.