Solid Object + Pathfinding = Huge Lag?

0 favourites
  • 5 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hello, I've been recently experimenting with solid objects in my game where all the enemies use pathfinding (and update their paths about every 0.35 seconds) to track the player and at least in theory, navigate around solid objects.

    I've had this problem earlier when trying to make a building and adding walls to it, and the AI had massive trouble getting around and often getting stuck running in a circle at the corner of the wall they were supposed to walk around to get inside and then get to me. I've given up my efforts on that for now because I've tried everything to try and make it work, but that's not why I'm here. It's a similar problem.

    I have this one very small solid object that is used as an upgrade station for the player. The shape of it is a simple rectangle (it's currently supposed to look like a metal table but that's very wip and being changed) and only used 4 collision points for it's collision box. When I put it in the game I noticed over time that when you were standing at the table or very close to it there would be massive lag that would slow everything down. I didn't know the cause until I played it without enemies and realized that it only lags when the enemies are trying to find a path to me to kill me. I've assumed this is related with that other problem I mentioned in the last bit of info a few lines up where the AI seems to have trouble navigating around seemingly simple objects. Funny enough, this time the AI doesn't get stuck in a loop of running in circles, they pursue me normally but if I'm near the table it will still lag massively.

    I have a video showcasing the game and the lag associated with this to make it easier to visualize and understand. Lag happens at around 0:03 and 0:14.

    If anyone has any idea as to why this is happening and has any solutions, suggestions, or ideas please comment below. It would be extremely appreciated as I would hopefully like to add actual obstacles and improve on the map I have in the game currently but simply can't due to the lag and pathfinding issues. Also, if anyone has any questions just in case there might be something I haven't mentioned contributing to he problem I would be glad to answer them!

  • What pathfinding cell size are you using? Is there enough "space" between your objects for the characters to properly and easily fit through? Have you tried running a quick function for "regen obstacle map around sprite.object" to see if that helps?

    Those are just the first few things I can think of that may be causing an issue.

    *EDIT*

    I just watched your video link. The lag doesn't seem super noticable to me but I can see a tiny bit of jank. How many enemies in total are in the layout and how big is your layout? Large layouts will cause jank when using pathfinding because of the sheer amount of calculations gets exponentially increased as the layout size gets larger. Also, lots of objects calculating paths all at one time can cause this.

    ~Sol

  • What pathfinding cell size are you using? Is there enough "space" between your objects for the characters to properly and easily fit through? Have you tried running a quick function for "regen obstacle map around sprite.object" to see if that helps?

    Those are just the first few things I can think of that may be causing an issue.

    *EDIT*

    I just watched your video link. The lag doesn't seem super noticable to me but I can see a tiny bit of jank. How many enemies in total are in the layout and how big is your layout? Large layouts will cause jank when using pathfinding because of the sheer amount of calculations gets exponentially increased as the layout size gets larger. Also, lots of objects calculating paths all at one time can cause this.

    ~Sol

    I'll try those suggestions you have, but I'm not sure if they will do anything considering you mentioned that lag can happen with large layouts and lots of enemies. My game has a layout size of 1708 x 1708 and is a wave / horde survival shooter kind of game. At max there are maybe 30 enemies? And at least there is 9 so I'm not sure if that is what is making the lag so bad but it probably is. Not really sure what qualifies as a "large layout" that is large enough to create lag.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > What pathfinding cell size are you using? Is there enough "space" between your objects for the characters to properly and easily fit through? Have you tried running a quick function for "regen obstacle map around sprite.object" to see if that helps?

    >

    > Those are just the first few things I can think of that may be causing an issue.

    >

    > *EDIT*

    > I just watched your video link. The lag doesn't seem super noticable to me but I can see a tiny bit of jank. How many enemies in total are in the layout and how big is your layout? Large layouts will cause jank when using pathfinding because of the sheer amount of calculations gets exponentially increased as the layout size gets larger. Also, lots of objects calculating paths all at one time can cause this.

    >

    > ~Sol

    >

    I'll try those suggestions you have, but I'm not sure if they will do anything considering you mentioned that lag can happen with large layouts and lots of enemies. My game has a layout size of 1708 x 1708 and is a wave / horde survival shooter kind of game. At max there are maybe 30 enemies? And at least there is 9 so I'm not sure if that is what is making the lag so bad but it probably is. Not really sure what qualifies as a "large layout" that is large enough to create lag.

    I'm working on some pathfinding type stuff right now as well, on a layout of 2000x2000 and up to 60 or so pathfinders.... and I don't get this lag. It's possible that I'm doing something differently to you, like offsetting the path calculations for the entities so they aren't all trying to find paths at the exact same time. I'm also using a cell size of 64, so it's also possibly related. I think the key to getting a good setup is the ratio between the actual layout size vs your cell size. Your layout could be 50,000px big if your cell size is say, 500px big.

    I'm not sure what else to suggest exactly, but maybe try playing around with the cell sizes and such - and make sure enemies aren't trying to re-calculate a path all at the same time. I simply made it so if the enemy is already moving along a path, to only calculate a new path every couple of seconds versus if they aren't moving at all to check more frequently (for faster initial response).

    Hope you figure it out.... seems like a bit of a weird problem. Also check the collision boxes for your enemies and objects and make sure they aren't too complicated. Having a complex collision polygon can cause a lot of lag as well when trying to figure out paths.

    ~Sol

  • Thanks a ton, I'll try changing up the cell size and how the pathfinding works a bit. All my enemies calculate new paths very often and at the same time so that is probably the problem!

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