How I can make a sticky block

0 favourites
  • 14 posts
From the Asset Store
Physics Block Puzzle game template for Construct 3
  • Hi everyone, sorry for my rude English))

    I need yours pro help. I have a procedural generating level - level has random count of square blocks. Simply solid square. And I have a mob on level. How it possible to make that levels' blocks make sticky for that mob? On screen you can see what I mean - I want that a mob walking nearby block everywhere - the red line shows the way of mob.

    How I can do it?

  • Hello Fakov !

    I'm not saying it is the perfect solution, I'm not a "pro" but here is a solution I've come up with :

    mediafire.com/file/7xbcx7rb9uk1f9t/ExerciseStickingMob.capx

    Everything is explained into the Capx, but to sum up, my method is :

    1/ Creating Nav Points around blocks, which the Mob will be able to follow.

    2/ When the mob reaches a Point, he decides where to go next by selecting another close point as long as he doesn't go backwards

    I hope it helps. I was unsure I'd be able to do it so I took it as a challenge ^^

    If someone has remarks regarding that Capx, I'm interested (for science !)

    ++

  • Hey ,

    Pretty cool example!

    I optimized it just a bit - removed some objects, instance variables and about half of the events <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    I'm not saying my code is better, it has its flaws and issues.

    As you said "just for science" <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.dropbox.com/s/7xre6gb6hv1yy ... .capx?dl=0

    I removed 8-direction and moving the sprite by simply changing its position by 1px.

    Probably a better solution would be to use MoveTo behavior, it has "On Reached Destination" event.

  • You can actually creating lines to guide object along the length:

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

  • Nice demo, alextro!

    Yeah, it's much easier if the path is predefined and you can place guiding lines or points along it.

  • Yeah alextro the line is definitely the best way to do it if the position of the tiles remains the same, but the challenge here was to create a path that can adapt if the Blocks are randomly positioned =)

    Really cool, straightforward Demo though !

    dop2000 : thanks for the improvements !

    • I like your way of creating every points and THEN deleting those we don't need. It's much more straightforward than my previous method.
    • Your idea of using Families instead of "Zones" to refer to two different points in a condition is neat.
    • You got rid of 8-dir behavior and now the movement of the sprite is continuous
    • Overall, great optimization !
    • I can't find any MoveTo behavior. Is it a plugin ?

    I tried to improve over your version one last time. The changes :

    • I've modified blocks' Imagepoints so that the sprite is really "sticking" to them and there's no margin.
    • It created new problematics namely in concave corners, where several points were slightly overlapping. Now they're considered "clones", and if one was the LastPoint, then neither it nor the clone is considered a potential target.
    • I've reworked the movement a bit so that the sprite never moves diagonally

    Here is the new Capx : mediafire.com/file/gkk4jd9n7bdmf4e/ExerciseStickingMob_dop2000_semoreh.capx

    Science, yay !

  • Yes, MoveTo is an external behavior by Rex.Rainbow, very simple yet very useful. I'm surprised why there is no standard behavior like that in C2.

    You over-complicated things again <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Here is an improved version with Sprite sticking to walls and moving in straight lines.

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

    Of course this example is far from universal, as it may not work correctly if the level configuration is different or if walls are thicker etc.

  • dop2000 I tend to do that, yes ^^'

    Well observed, important corners were indeed overlapping either 0 or 2 other points. I hadn't noticed that and it led you to this version !

    I've toyed with the demo and it works fine now except I detected a problem if the sprite moves in a U shaped zone. Sometimes it will take an unauthorized shortcun, cutting through the air. That's why I added instances variables in each Points, storing the authorized moves from there so that the Sprite can check them when it's looking for a new target.

    Again, maybe it's not optimized but it works.

    Well, I think we're close to having our final build here. I hope it will be useful to someone (OP ?). I know I'll maybe use it some day myself

    The link here (I'll try to keep it store for a long time for those interested) for the last version :

    mediafire.com/file/lu1fk1dwnzyt3de/ExerciseStickingMob_dop2000_semorehV2.capx

    Cheers !

  • Yeah, like I said this method is not very "universal". One small change in your latest version and the enemy sprite gets stuck:

    I think this idea might work better (inspired by maze solving algorithm) -

    Create an invisible square block (green) under each tile, slightly bigger in size.

    Move Enemy sprite along the edge of this green block, from corner to corner (clockwise).

    When Enemy is overlapping next block - "jump" to the next block and continue moving in straight line.

    If Enemy is overlapping two other blocks, pick the block which is to the left from the current movement line, and jump to this next block.

    This can actually be done without the green blocks, it's just easier to explain with them.

    Don't ask me for a demo, I've spent too much time on this already

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ,

    You know what, scrap my previous comment. Scrap everything!

    Here is an extremely simple solution:

    https://www.dropbox.com/s/5u73vndufc28r ... .capx?dl=0

    Yes, the enemy face hits the wall in corners a little bit, but it's a small price to pay for the simplicity! <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Ah it reminds me of my old tutorial to auto generate border around blocks:

    https://www.scirra.com/tutorials/1344/e ... -generator

    Some process need to be automated so we can spend more time on other areas.

  • dop2000

    Hum, interesting. Extremely Simple indeed.

    (I just don't understand why the Red Dot is always considered "overlapping" one Block, when he clearly is only touching with the side which I thought shouldn't be considered "Overlapping").

    I still like our previous method. You got stuck because the gap was too narrow, and it can be solved by augmenting the number of nav points I suppose :3

    But yeah, we're going a little too far maybe. There are plenty of ways to deal with this problem and every project will have different needs.

    alextro : I can see the resemblance

    Cheers, see you around !

  • , red dot shares 1px with the Bloc, it's enough to be considered overlapping.

    Here is the final fixed version, still with only 6 events:

    CAPX

    EDIT 2 years later: If anyone stumbles upon this post, here is a much better version:

    dropbox.com/s/8jbp3p7zlra5355/WalkAroundWalls2.capx

  • Well, now I must recognize it is the best version for sure. It'll probably help a lot of people, congrats

    ++

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