Find path to sprite in general, not image point?

0 favourites
  • 10 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • 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. dl-web.dropbox.com/get/zombie-movement.capx

  • Sorry about the link, I put it in a url tag but it didn't work apparently.

  • 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.

  • There is also the possibility to use the coordinates of the bounding box of the base if that would suit your needs.

  • On collision with base -> stop pathfinding. Would that work?

  • 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 :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

    dl.dropboxusercontent.com/s/yplfoqmlv034tfu/zombie-movement.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.

  • 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

  • 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.

  • 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 :)

    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 :)

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