GLBasic forum

Main forum => Tutorials => Topic started by: doimus on 2010-Mar-11

Title: Few collision questions
Post by: doimus on 2010-Mar-11
I have a few questions regarding 2D collision implementation.

Take a look at attached image.

(http://img297.imageshack.us/img297/3186/coldo.png)
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.



Title: Re: Few collision questions
Post by: Kitty Hello 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)
Title: Re: Few collision questions
Post by: doimus 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 (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.

Title: Re: Few collision questions
Post by: Kitty Hello on 2010-Mar-11
http://www.glbasic.com/showroom.php?site=games&game=AC3DPoly (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.
Title: Re: Few collision questions
Post by: doimus 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:

Title: Re: Few collision questions
Post by: Kitty Hello on 2010-Mar-18
the qsqr function is in the qmath.gbas file in samples/common.
Title: Re: Few collision questions
Post by: Hooka 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...
Title: Re: Few collision questions
Post by: Scott_AW 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.
Title: Re: Few collision questions
Post by: Kuron on 2010-Apr-22
QuoteIs 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.

QuoteAnd 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 ;)