How do I Make My Enemy Pathfinding Reliable

0 favourites
  • 8 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hello!

    This is my very first post, sorry if I do anything wrong...

    I'm working in Construct 2, on Windows 10.

    I'm working on a game with enemies walking from waypoint to waypoint. Right now I'm using the Pathfinding behaviour and containers. The enemy is in a container with 4 waypoints, and it cycles through each waypoint setting the path each time it arrives to the chosen waypoint. Things work fine when there is one enemy, but copying and pasting making 2 instances of the enemy causes some weird things to happen. I'm used to Unity's prefabs where I can make one and place them multiple times in a scene, is there another way to do this in Construct?

    I tried using unique ID's as well but couldn't fully grasp the concept.

    Questions I'm asking:

    Is there a way to have multiple instances of one enemy object following their own waypoints?

    Are containers a good substitute for Unity's prefabs?

    Also, how do I upload cap.x file?

    Here's the google drive link for the cap.x https://drive.google.com/file/d/0B0Lmgx9nyVMATzZFUHk3TEk3QXc/view?usp=sharing

    Thanks in advance for any comments!

  • Instead of copying the sprite clone it and then it is a unique sprite you can set with different path finding behaviors.

    When you create sprites they can be set at the time of creation with different path finding behaviors.

    If you want some wandering add in a Sine effect.

    Upload your capx to a server like dropbox and then you can link it with URL in the forum editor.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't really want to clone these enemies because I'm not sure how many I will have on each map, I like keeping "scalability" (i don't think that's a word). All the enemies have the same behaviours and react to the player the same, it's just the waypoints and positioning are different. I suppose I could clone them and put them all into an enemy family, but is that more expensive on memory than copy and pasting?

  • Pick by UID and then use UID to set unique behaviors if they're static enemies (i.em are predefined per map)

    You can do either of these.

    A, Use this action to pick by UID, and be sure to do it right after an enemy is created (if not created on runtime):

    int(Enemy.UID)

    B, Or just look at an instance in your editor to get the UID you want.

    Also, you should learn to use families for managing enemies, yes, it makes for a lot cleaner design.

  • DevinMurray

    Coming from Unity, you got to 'forget' a few things.

    Plz read this first: https://www.scirra.com/manual/75/how-events-work

    I changed some things in you capx.

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

    If you have read that 'how events work' then i can introduce you to the 'picklist'. Do not read conditions as 'if this .. then that'. Read them as 'what do they add/remove from the 'picklist'.

    If you look at my capx, to event nr 4. This reads as ...

    Pick each instance obj_enemy one by one. The picklist contains now that one obj_enemy.

    Add all instances of obj_waypoint's who's instance variable 'BelongsTo' is the same as the instance variable 'Owner' for the previous picked obj_enemy to the picklist. The picklist contains now that one obj_enemy instance + 4 obj_waypoint instances.

    Pick from the previous picked obj_waypoint's the one instance with instance variable 'order' = zero. The picklist contains now one obj_enemy + 1 obj_waypoint

    The action(s) now work only with those two instances of the two sprites in the picklist.

    That is, in a nutshell, the base of C2.

  • I don't really want to clone these enemies because I'm not sure how many I will have on each map, I like keeping "scalability" (i don't think that's a word). All the enemies have the same behaviours and react to the player the same, it's just the waypoints and positioning are different. I suppose I could clone them and put them all into an enemy family, but is that more expensive on memory than copy and pasting?

    You can pick individual sprites by the UID and using families makes it easier to manage enemies but isn't necessary.

    I just use variables for settings I want changed or to randomize behaviors and when that sprite is created in the same event change the path finding setting directly or using variables.

    Everyone has a different way for accomplishing things. I tend to go the easy route that I know works every time lol!

  • Oh wow! I was reading the event page wrong this whole time, thank you.

    I never thought to reference the waypoint in the condition.

  • Oh wow! I was reading the event page wrong this whole time, thank you.

    I never thought to reference the waypoint in the condition.

    Once you get the hang of it, you will love it.

    There are still some quirks to overcome. But those you meet when its time.

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