How do I Make My Enemy Pathfinding Reliable

Get help using Construct 2

Post » Tue Feb 28, 2017 4:32 pm

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!
B
5
Posts: 9
Reputation: 248

Post » Tue Feb 28, 2017 5:35 pm

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.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Tue Feb 28, 2017 5:56 pm

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?
B
5
Posts: 9
Reputation: 248

Post » Tue Feb 28, 2017 6:00 pm

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.
Zelda Gamekit (my project)



Example capxs:

Zelda-Style Inventory

Zelda Health

3-saveslot system

[url=https://www.dropbox.com/s/d4396pwak0oh7q6/ZeldaDialogueSystem.capx?dl=0]Zelda-like Dialogue[
B
51
S
24
G
30
Posts: 534
Reputation: 19,620

Post » Tue Feb 28, 2017 6:01 pm

@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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Feb 28, 2017 6:25 pm

DevinMurray wrote: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!
Last edited by lamar on Tue Feb 28, 2017 6:32 pm, edited 1 time in total.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Tue Feb 28, 2017 6:31 pm

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

I never thought to reference the waypoint in the condition.
B
5
Posts: 9
Reputation: 248

Post » Tue Feb 28, 2017 6:35 pm

DevinMurray wrote: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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: AllanR, brunopalermo, farsen, ST314, TheRealDannyyy and 37 guests