Author Topic: Few collision questions  (Read 4433 times)

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Few collision questions
« on: 2010-Mar-11 »
I have a few questions regarding 2D collision implementation.

Take a look at attached image.


Let's assume that brown splotch is a walkable area and white is not-walkable. There are those three sprite dudes trying to walk around.
I need the most efficient routine to implement collision detection.

Here's how I do it at the moment:

1) draw a huge full-screen "pixel" with non-walkable area filled and walkable area as transparent
2) draw small sprites (yellow lines) that serve as base-line for the players
3) check for SPRCOLL between 1) and 2) - that way I prevent things like blue dude from happening.
3) then draw actual background and actual characters, so those "helper" sprites are never seen by players
4) showscreen

Am I doing it right or is there a simpler way?



Another question:
Is it possible to check for collision between a box(start,x,y) and a sprite? And is it possible to check for collision between sprite and non-sprite objects? Like between line and sprite?
Something like collisions in 3D: sphere with object, ray with object, etc.




Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Few collision questions
« Reply #1 on: 2010-Mar-11 »
If you have that complex and big objects, why aren't you using a polygon shape thing for that?
The AC3D library can handle polygonal shapes and collision detection (much much faster than per pixel with these big elements)

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: Few collision questions
« Reply #2 on: 2010-Mar-11 »
What's AC3D library?
By polygon shape, you mean I should use 2D polyvector commands in GLB, or I should switch to textured 3D polygons and do collision checks in 3D?

I'm aware of polygon-shaped collision detection in 2D engines, for example how it's implemented in Torque Game Builder:
http://docs.torquepowered.com/tgb/official/content/documentation/Component%20Tutorials/WYSIWYG%20Editing/Collision%20Polygons.html
but I'm not exactly sure how to utilize this technique in GLB.


Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Few collision questions
« Reply #3 on: 2010-Mar-11 »
http://www.glbasic.com/showroom.php?site=games&game=AC3DPoly
With that library you can load .ac files (very very simple text files) and display them. But no need to display, you can just use it for collisions as well.

Offline doimus

  • Dr. Type
  • ****
  • Posts: 284
    • View Profile
Re: Few collision questions
« Reply #4 on: 2010-Mar-16 »
I tried to run AC3D library but got syntax error reported on preprocessor commands (?IFDEF debug). I bypassed that manually, but then QSQR function is not recognized - syntax error too.

I'm on the latest IDE version - 7.285.  I have even downloaded from website and reinstalled  - but no success. :giveup:


Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Few collision questions
« Reply #5 on: 2010-Mar-18 »
the qsqr function is in the qmath.gbas file in samples/common.

Offline Hooka

  • Mc. Print
  • *
  • Posts: 3
    • View Profile
Re: Few collision questions
« Reply #6 on: 2010-Apr-18 »
And if anybody's wondering about weird errors spit out by qmath stuff, just change the RETURN to lowercase and all is well ;)

Kitty Hello, I might need to bug you for some help with this later as I need to do mouse click detection in triangular tiles...

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: Few collision questions
« Reply #7 on: 2010-Apr-22 »
You can have a sprcoll check using a simple sprite with the mouse's x & y coordinates.  You don't have to draw any sprites to do a sprite collision.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline Kuron

  • Mr. Polyvector
  • ***
  • Posts: 238
    • View Profile
Re: Few collision questions
« Reply #8 on: 2010-Apr-22 »
Quote
Is it possible to check for collision between a box(start,x,y) and a sprite?
Yes, you would use simple box collision to test between a box and a sprite.  This is so commonly used in games and apps, that it is built into the Windows API. 

"Gaming languages" have pixel perfect sprite collision commands, but in professional development this would almost never be used.  Instead you would use reduced/shrunken box/rectangle collision.

Quote
And is it possible to check for collision between sprite and non-sprite objects? Like between line and sprite?
The example you just asked about is the same as the question above.  A line is simply a really long and very short box ;)