Few collision questions

Previous topic - Next topic

doimus

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.




Kitty Hello

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)

doimus

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.


Kitty Hello

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.

doimus

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:


Kitty Hello

the qsqr function is in the qmath.gbas file in samples/common.

Hooka

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...

Scott_AW

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/

Kuron

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