0 Favourites

enemy behavior - crawl around platforms [SOLVED]

This forum is currently in read-only mode.
  • I've been struggling with this enemy behavior for hours now and can't seem to come up with a decent solution. The game is a platformer, BTW. What I'm looking to do seems simple enough and is illustrated by this image. I just want the enemy to follow along the edge of a tiled background objects.

    <img src="https://dl.dropbox.com/u/28484936/enemy_problem.png" border="0" />

    Think of those little spiny enemies in Metroid that can crawl around a platform.

    <img src="http://www.consoleclassix.com/info_img/Metroid_NES_ScreenShot4.jpg" border="0" />

    I've been using a lot of "overlap at offset" events to set the enemy's speed and direction but I keep ending up with the object floating into space or moving through the background. The only solution I can come up with is to place a series of sprites at the corners that act as sensors, but it's not a very elegant solution. If anyone has an idea on how to make this work, I'd really appreciate it.

  • Maybe attach invisible detector sprites to each of the four sides of the sprite using image points. Then check which detector sprites overlap a tiled background to find where to go.

    I can give this a try later this week if you'd like an example.

  • robit_studios

    Hi this may help you...

    Stick to Plattaform

    The key is where to put the gravchangers... and you may use the dummyplayer to attach your real player or enemy sprite...

    there is another method if you dont like active one...

    PD: sorry my english...

    ^_^

  • Jayjay - I've considered this idea but I don't think it'd give me much more of an advantage over just using "overlap at offset" events. Maybe I'm wrong though?

    Yaottabyte - Thanks for taking the time to make that example. This is actually similar to how I have the enemy setup currently. It definitely works but I was hoping to find a method to avoid having to put a bunch of sensors on the corners of all the platforms.

    Ok, I put together an example CAP. If you try this you'll see that it works SOMETIMES.. but other times the enemy just randomly flys off the screen. It uses "overlap at offet" and "overlap at point" to detect the edges.

    https://dl.dropbox.com/u/28484936/crawling_enemy.cap

    Edit: Ok, after toying around with FPS settings I see now that the problem has everything to do with how fast the enemy is going. If I set the enemy speed to 80 - no problems. If I set it to 120 if will occasionally fly away. If I turn off v-sync and pump up the FPS to 200 I can make the enemy move very fast with no problems. Since I can't expect the game to run at 200 FPS I still need to come up with a solution for this.

  • Could you do something simple like have the enemy always have a movement component toward the center of the platform and then a separate movement component perpendicular to that? The math might be a bit unintuitive if you want to get consistent movement speed along the edge of the platform, but should be simple enough. I think there's Actions in the Custom Movement behavior that will allow you to turn an enemy to face toward an object all the time, etc.

    Alternatively, maybe you can use the platformer behavior to set gravity direction be toward the center of the platform, which is the same as above but might save you some time doing calculations.

    I can try to put it together later today when I get home, since it seems like a fun problem to solve.

    Also, check out this plugin, maybe it can do what you want:

    scirra.com/forum/path-movement-behavior_topic39306.html

  • And like that?

    edit: ops, didn't read Juryiel's post entirely^^. Well, now you even have an example .cap of his suggestion.

  • zyblade Thanks for the example. I considered the path movement option, but it won't work for my purposes. I don't want the enemies to have a fixed path. I want the enemies to be able to thrown off of their platform and attach themselves to wherever they land and continue moving.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • zyblade, robit_studios is right i'd tryed path behavior too but with odd results, i'll try something at home this night(Venezuela hehe) well tomorrow i'll post results...

    EDIT: almost i forgot, robit_studios try in my example, there is a method inside a disabled group thats quite different to sensor method, i'll change methods in my above post check it again!.

    EDIT 2: ready try again my example was updated, ignore gravChangers they are there because old method, now using a new method try to play with plattaforms to get desired results...

  • Yaottabyte I really like your method of changing the direction of gravity but I've run into one problem. I'm using Tiled Background objects for my platforms and there doesn't seem to be a way to "Pick closest to" for Tile Background objects.

  • no matters just use my dummy plattaforms and overlaps yours TB then make them invisible at start... they works as references...

    EDIT: added some tiledBackgrounds to show how use the method with yours...

    EDIT 2: a last tip, to my plattaforms dummies uncheck the plattaform attribute, and check it to your TiledBackgrounds so enemies move over your TBs and use the dummies as references to change gravity...

  • zyblade Thanks for the example. I considered the path movement option, but it won't work for my purposes. I don't want the enemies to have a fixed path. I want the enemies to be able to thrown off of their platform and attach themselves to wherever they land and continue moving.

    link

    With following layer if too close^^ and moving back to path, if you are too far away from the enemy.

    I didn't pay much attention to setting up the path movement exactly.

    This is just an example and it could look much better if you rearrange the path.

  • Thank you everyone for all your help, suggestions and examples. I'm happy to report that I got this working exactly the way I wanted it to. It took a lot of trial and error but the end result was worth it.

    To fix my problem I just tested for when the object reached the corner of a platform. Then test a "collision at offset" in all four diagonal directions. When if hits a platform is sets the X and Y position of the enemy to the edge of that platform, rotates the direction 90 degrees and sends it on it's way. I can now set the enemy to any speed less than 650 and it seems to work great.

    Here's a cap if you want to check it out. If you see anyway I can make this even more efficient let me know.

    https://dl.dropbox.com/u/28484936/crawling_enemy_2.cap

    Thanks again.

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