Pixel based collision?

0 favourites
  • 9 posts
From the Asset Store
Particles support animations, collisions, effects and etc.
  • I've been looking around the forums but couldn't find anything.

    Does anyone know how to go about if you wanted to do destructible terrain and pixel based collision similar to Worms:

    I wanted to play around with some similar functionality.

    My first guess is that I would have to use some plugin like canvas or paster, when I could get the Alpha value of a certain pixel?

    Has anyone played around with something like that and have an example lying around, or know where to start?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • This is possible with tilemap, see this post, there are lots of useful info:

  • Thanks dop2000 just found that thread as well. Found another one too but that required Canvas plugin, which hasn't been converted to C3.

    I'm gonna try use the tilemap approach for experimentation.

  • IIRC, LootBndt was messing about with this in December - there were a few GIFs on their Twitter. (Quite far down though, prepare for a lot of scrolling!)

    Could be worth pinging them?

  • I was thinking of a solution like this. The destructible terrain would be no problem, if I could just mask out alpha from the terrain, then use raycasters, and at the tip of each raycaster i would check what the RGBA was, to restrict movement to the raycaster length.

    Unfortunately I can't find a way to check the Alpha at a Certain pixel for a certain layer or a specific object.

    I think that the canvas plugin can read the rgba at a certain point, but this is such a simple thing so I hope some day that Ashley implement a built in way to get the RGBA of a certain pixel for that specific layer, instead of having to rely on 3rd party plugins that may or may not be converted or maintained.

    Raycaster is also one of those has to have things that should be in the engine as standard.

  • I think you can do this without the pixel RGBA check.

    You will mask out the terrain using invisible sprites, right?

    You can make your own version of raycaster. To check if there is a wall on the right, move a virtual point from the character to the right, constantly checking if this point is overlapping terrain and not overlapping masking sprite.

    For x=player.x to (player.x+50)

    ...Pick terrainSprite overlapping a point (loopindex, player.y)

    .......Pick maskSprite overlapping a point (loopindex, player.y)

    .......Else -> set wallDetected=1 ; Stop loop

  • dop2000

    Yes I know how to make a raycaster with events. This is not the big issue.

    I'm not sure the masking sprite would work. Yes you can mask out Graphics with sprites using blend modes, but the raycaster would need to check the collision polygon to know where to stop. You can't tell the ray to stop at if a certain pixel that has an Alpha higher than 0.

    If a ray stretching from the player towards a wall with a hole, how does the ray know which area that is the hole, and not stop there, and continue to look for a wall?

    I think you would need to check the alpha of an X, Y position on a layer, in order to get a very accurate stopping point for the raycaster.

  • Not sure I understand. What's the problem with checking the collision polygons of mask sprite?

    Here, I made a demo:

    https://www.dropbox.com/s/86haw9omeh68q ... .capx?dl=0

    Circles are a bit rough, you can add more points to their collision polygon to make them smoother.

  • Ahhh I see what you mean. I was having a hard time getting the loop to continue after hitting the first object, my raycaster worked a bit different.

    I managed to update your example to something more along the lines what I was thinking. Although I have to update that raycaster to use increments to be a bit more lightweight, and add one for each direction of the character, but it would look something like this.

    https://www.dropbox.com/s/wmdyqdiat4lcg ... l.c3p?dl=1

    But this could definitely work I think.

    Adding physics to a character he could use this method to navigate a would with holes. masked with sprites.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)