April 6, 2018 at 1:00 pm #14272
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?April 6, 2018 at 2:57 pm #14273
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:April 6, 2018 at 4:05 pm #14274
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?April 6, 2018 at 6:47 pm #14275
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!April 6, 2018 at 11:18 pm #14280
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?April 6, 2018 at 11:58 pm #14281
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…April 7, 2018 at 11:20 am #14282April 7, 2018 at 11:21 am #14283
@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.April 7, 2018 at 12:43 pm #14284
See my previous post if you fancy a porting job, but also this:
You can install via the Ted2Go module manager (Build menu) and try the examples in the module folder.April 7, 2018 at 2:51 pm #14285
You must be logged in to reply to this topic.