Not wanting pixel perfect collision

Previous topic - Next topic

Widget101

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.

Qedo

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

Widget101

#2
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!




Moru

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/

MrPlow

That manic miner looks really nice btw :)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

StevetS

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:
PLOT 50,50:DRAW 50,50,45454545

erico

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

dreamerman

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.
Check my source code editor for GLBasic - link Update: 20.04.2020

spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/