How to use Pathfinder efectively?

Get help using Construct 2

Post » Wed Jun 26, 2013 6:50 pm


Im experimenting with the pathfinder behavior, and have found it can cripple the CPU. Im doing an RTS, and as soon as the unit number gets slightly high (around 20) the frame-rate drops to it's knees.

My guess is I'm not using it efficiently, but I have not found examples of tutorials on how to use it well; how to use it so that it doesn't melt the CPU.

Any thoughts?
Posts: 53
Reputation: 2,459

Post » Wed Jun 26, 2013 8:33 pm

What setup do you use ? Grid size ? Do you have any moving obstacle and/or regular "regenerate obstacle map" ?
Once the obstacle map is generated, paths are computed on demand, and a path asked multiple times is search only the first time (it directly triggers the OnPathFound next times).
If you have a path finding on every unit, and if every unit is itself a moving obstacle, and all move simultanously, yes, your CPU will melt. I will then melt again, and again, just to say it's not happy.
Moving obstacles in particular are a biiiiig hit on the FPS as they disable the behavior's "cache".
Knowing more on your game could help detect the problem though.
Posts: 473
Reputation: 6,321

Post » Wed Jun 26, 2013 9:34 pm

I'd be interested to know more about your project, too.

I built a quick test with grid size set to 16 and a room filled with moving solid objects. It generates a new pathfinder object every 0.25 seconds and every object gets a new unique path every 1 second. I watched it climb to 300 objects before I got bored, and by then it still sat solid at 58-60fps.

I did notice that when the grid size dipped to around 8, I got stutters every second, but I can't imagine that anything less than 16 would be required.

Even 32 would work fine in an RTS. Consider the grid-based construction of even a modern RTS like Starcraft II - that goes a long way to assist in speeding up the engine.
Posts: 912
Reputation: 12,656

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests