How do I find a path to a moving object?

Get help using Construct 2

Post » Wed Mar 18, 2015 9:42 am

How do I use the Pathfinding feature to follow a moving object. So far I have this code but it just crashes my game when I click a monster outside of the basic_attack_radius variable:

Image
B
3
Posts: 9
Reputation: 193

Post » Wed Mar 18, 2015 2:11 pm

The pathfinding behavior is very CPU intensive. In your code, you are using a loop inside which you are finding a path. This starts the process of finding a path repeatedly and you will eventually run out of processing power to complete the task so, it is no wonder the game is crashing. Have you read through the documentation and tutorials on pathfinding? If you had, you would see this is not how to use the behavior.

There is a really good tutorial on combining 2 behaviors to get an enemy to chase the player:
https://www.scirra.com/tutorials/474/pa ... e-of-sight

Read through it. You may find an easy way to do what your are trying to do. Also, make sure to read all the documentation on the pathfinding behavior in the manual and check out a couple other tutorials.

I hope that gets you what you need and good luck with your project.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Wed Mar 18, 2015 4:57 pm

how about this: (kamikaze enemies move towards you, that's a instance variable) and other move toward where they were randomly assigned.

if your obstacles are static you can remove regenerate obstacle map. also make sure your item that you follow isn't a obstacle.
You do not have the required permissions to view the files attached to this post.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
39
S
14
G
12
Posts: 617
Reputation: 9,297

Post » Wed Mar 18, 2015 11:16 pm

FragFather wrote:The pathfinding behavior is very CPU intensive. In your code, you are using a loop inside which you are finding a path. This starts the process of finding a path repeatedly and you will eventually run out of processing power to complete the task so, it is no wonder the game is crashing. Have you read through the documentation and tutorials on pathfinding? If you had, you would see this is not how to use the behavior.

There is a really good tutorial on combining 2 behaviors to get an enemy to chase the player:Read through it. You may find an easy way to do what your are trying to do. Also, make sure to read all the documentation on the pathfinding behavior in the manual and check out a couple other tutorials.

I hope that gets you what you need and good luck with your project.


Thanks for the information. I'm going to do more in-depth research into the pathfinding behaviour. One question, I thought about the processing intensity for the CPU, that's why I added the wait action but it doesn't work, can you shed some light on that?
B
3
Posts: 9
Reputation: 193

Post » Thu Mar 19, 2015 1:41 am

Take a look at this:
https://www.scirra.com/tutorials/723/us ... t-in-loops

The wait only stops the follow path event. The loop continues processing the next iteration immediately.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712


Return to How do I....?

Who is online

Users browsing this forum: bbjGames, bigcatrik, Exabot [Bot], Governador, mekonbekon, menos30, newt, tarek2 and 12 guests