Author Topic: Not wanting pixel perfect collision  (Read 932 times)

Offline Widget101

  • Mc. Print
  • *
  • Posts: 24
    • View Profile
Not wanting pixel perfect collision
« 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.

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 350
  • to program what I have todo how should I program?
    • View Profile
Re: Not wanting pixel perfect collision
« Reply #1 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

Offline Widget101

  • Mc. Print
  • *
  • Posts: 24
    • View Profile
Re: Not wanting pixel perfect collision
« Reply #2 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!



« Last Edit: 2021-May-08 by Widget101 »

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1791
    • View Profile
    • Homepage
Re: Not wanting pixel perfect collision
« Reply #3 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/

Offline MrPlow

  • Prof. Inline
  • *****
  • Posts: 1784
    • View Profile
Re: Not wanting pixel perfect collision
« Reply #4 on: 2021-May-17 »
That manic miner looks really nice btw :)
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

Offline StevetS

  • Mc. Print
  • *
  • Posts: 9
    • View Profile
Re: Not wanting pixel perfect collision
« Reply #5 on: 2021-May-23 »
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

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4396
    • View Profile
    • FUED
Re: Not wanting pixel perfect collision
« Reply #6 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

Offline dreamerman

  • Global Moderator
  • Dr. Type
  • *******
  • Posts: 394
    • View Profile
    • my personal website
Re: Not wanting pixel perfect collision
« Reply #7 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.
Check my source code editor for GLBasic - link Update: 20.04.2020

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3956
    • View Profile
    • Space Fractal
Re: Not wanting pixel perfect collision
« Reply #8 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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.