Find path to sprite in general, not image point?

Get help using Construct 2

Post » Thu Jul 04, 2013 7:49 am

Hello,

I'm attempting to get my little zombies (red squares) to find a path to the human base (green rectangle), and then once they collide with it, they flash to signify that they are attacking it.

However, all zombies automatically target the Origin image point of the base, so they tend to end up piling up in the center base all together.

How can I get them to simply walk to the nearest part of the base instead of an image point. Is there a better solution that I am not aware of?

Thanks ahead of time. Here's the .capx if you need it. Nothing special currently. https://dl-web.dropbox.com/get/zombie-movement.capx?w=AABYIH-ieaApq_FWPxBkyfnpA79TDNsneP74re49_l5aQA&dl=1
B
3
Posts: 6
Reputation: 187

Post » Thu Jul 04, 2013 7:50 am

Sorry about the link, I put it in a url tag but it didn't work apparently.
B
3
Posts: 6
Reputation: 187

Post » Thu Jul 04, 2013 10:12 am

@Tylairus

Your link doesn't work for me. Probably your file isn't in a public folder or the link you've provided isn't a public link.

Without the capx though, maybe I can give some advise. You could give the base multiple imagepoints and compare the distance the zombie is from them and make them go to the nearest one. Also you could choose to use invisible sprites instead of imagepoints.

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 04, 2013 10:14 am

There is also the possibility to use the coordinates of the bounding box of the base if that would suit your needs.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Jul 04, 2013 2:11 pm

On collision with base -> stop pathfinding. Would that work?
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,610

Post » Thu Jul 04, 2013 2:27 pm

If you want an enemy to go into the base, you need to tell him where exactly. Your problem, if I understand right is that they all stack in the center. So don't do "Find path to hangar", but "Find path to (X,Y)" where X = hangar.X+random(hangar.Width) and Y = hangar.Y+random(hangar.Height); they will all find their way to a random point inside the hangar. If your problem is that they should stop moving once inside the hangar, ramones' solution is the one you need :)
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Thu Jul 04, 2013 7:29 pm

Thanks for the replies
Ooops, I just made that Dropbox for this reason so I didn't know. Here's the link they give when you click share, and it appears to work when I'm logged out. Also, turns out new users can't use the URL bb code, so I guess this long annoying url will have to do.

https://dl.dropboxusercontent.com/s/yplfoqmlv034tfu/zombie-movement.capx?token_hash=AAH2EH8kFTtcxzFmbVtLuEh12vbR_pI9jI0TYUlKV_ncew&dl=1]capx

@LittleStain - I thought of random image points scattered throughout it, but wasn't sure how to target a specific one. If I remember correctly, I didn't see an option to choose which image point it would path find to.

@ramones - That's actually what I'm doing now. That is working pretty well, except since the zombies all target the origin of the object, they typically end up stacking since they funnel towards to middle as they walk to it.

@Guizmus - That sounds like it may be a solution for this. I'm going to give it a try right now.

I'll post back with any updates, thank you all for your responses.Tylairus2013-07-04 19:31:45
B
3
Posts: 6
Reputation: 187

Post » Thu Jul 04, 2013 7:41 pm

I would make the base out of multiple pieces, make the pieces sprites in a family, and have the zombies pathfind to the nearest piece using something like pick nearest. Then have them attack. Use a variable to store the bases health, and each time a zombie hits a piece of it subtract from the overall base health. With this you could make individual pieces of the base destructible or just have the whole base destroyed when it's health hits 0
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,568

Post » Thu Jul 04, 2013 7:48 pm

That's an excellent idea. My final goal will be to have a base with multiple different pieces which can be upgraded by the player and tore down by the zombies, so that is close to what my thought was.

Ideally, I'd like the zombies to try to path find into the base, but if they can't reach it, attack the nearest base piece.

Thanks for the response. I appreciate the insights and I'm going to give them a try today.
B
3
Posts: 6
Reputation: 187

Post » Thu Jul 04, 2013 7:57 pm

[QUOTE=Guizmus] If you want an enemy to go into the base, you need to tell him where exactly. Your problem, if I understand right is that they all stack in the center. So don't do "Find path to hangar", but "Find path to (X,Y)" where X = hangar.X+random(hangar.Width) and Y = hangar.Y+random(hangar.Height); they will all find their way to a random point inside the hangar. If your problem is that they should stop moving once inside the hangar, ramones' solution is the one you need :)[/QUOTE]

Yeah quality answer, after that add a little 1 or 2 seconds wait then repeat so they keep recalculating to random points in your hanger so its more realistic and chaotic :)
B
4
S
1
Posts: 51
Reputation: 502

Next

Return to How do I....?

Who is online

Users browsing this forum: Ajbael, DolyGamesCosmos, lukezero, RoaringPixels, Solomon and 9 guests