Sprite collision?

About Monkey 2 Forums Monkey 2 Programming Help Sprite collision?

This topic contains 9 replies, has 5 voices, and was last updated by  SekaiChi 1 week, 5 days ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #14272

    SekaiChi
    Participant

    I’m struggling with collision I know about box collision and that’s all good but how do you do pixel perfect collision with sprites?

    #14273

    Ethernaut
    Participant

    There’s no pixel collision out of the box in Monkey2.

    Mind if I ask, why do you need pixel collision? If you use something like The Timelinefx module you can get super fast 2D polygonal collision with collision reactions:

    TimelineFX module version 1 for Monkey2 available

    #14274

    SekaiChi
    Participant

    I’m making a Lemming-like game that’s very detailed at the pixel level, I guess I could make use of a polygon collision routine but I would rather build one myself than use system (personal preference).

    Are there other examples there how to do that kind of thing as I’m totally beginner with polygons. What’s a “transformed” polygon? http://mojolabs.nz/codearcs.php?code=1676

    Are there any rules on what polygons are possible in Monkey2? do they have to be convex or concave?

    #14275

    Ethernaut
    Participant

    This series will probably teach you way more than you actually need to know about transformations!

    Bottom line: a transformed polygon is the original polygon + translation, rotation and scale.

    The cool thing about doing things this way is that it’s resolution independent. Pixel checking for collisions in an HD game would be very inefficient, with perhaps millions of checks per frame!

    You also get more information out of a polygon collision, like the collision normal (the direction it is pointing at).

    Another advantage is that the same methodology applies to 3D, so learning to deal with 2D polygons “prepares” you for some key 3D concepts.

    If your game really depends on pixel collision (destructible terrain, etc) you can still use a small rectangular collision area in the character, instead of the whole sprite, and check for pixel collisions just in a handful of coordinates.

    Good luck!

    #14280

    Milamber
    Participant

    Hi.  I`m a newbie to the way Monkey 2 operates too.  Can an invisible sprite/polygon be used for collision checks along side a controllable visible image?

    #14281

    Mark Sibly
    Keymaster

    There is no collision detection built into ‘stock’ 2d monkey2 so you’ll need to look into either writing your own or using modules like chipmunk, pyro or timelinefx etc.

    The way I used to do pixel perfect collision back in the day was to build a ‘bitmask’ of solid pixels, and ‘and’ masks together and check for non-0 results. That’s probably overkill for modern retina res devices so a polygon collision check might be the way to go there – not quite as precise though…

    #14282

    DruggedBunny
    Participant

    That collision code’s here, for what it’s worth. (Ctrl-F -> colli)

    #14283

    SekaiChi
    Participant

    @ethernaut Great explanation, thank you very much for the replies!

    @Mark Sibly Good idea. I would like to try both polygons and masks.
    Are there any GLSL variables of types atomic_uint and atomic_int (adders) on Android and iOS?
    If they do exist they could used for pixel exact collisions with some trickery I think, and they would work even with rotation and scaling.

    #14284

    DruggedBunny
    Participant

    See my previous post if you fancy a porting job, but also this:

    module PNG2Polygon

    You can install via the Ted2Go module manager (Build menu) and try the examples in the module folder.

    #14285

    SekaiChi
    Participant

    @druggedbunny Wow that’s really interesting. Handy!

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.