How can I prevent the game from lagging due to Pathfinding's behavior?

Not favoritedFavorited Favorited 0 favourites
  • 9 posts
From the Asset Store
HTML5 Game Bundle (7 Games) – Created with Construct 3
  • Hi, I'll try to be as clear as possible, even though I'm using Google Translate because my English isn't great. I've had this happen in several games where I use pathfinding behavior, and the game runs incredibly slowly, sometimes even dropping to 0 frames per second.

    This has happened especially in a first-person shooter, although at first I thought it was because of the 3D camera, since Construct 3 is a 2D game engine (or so they say), but then I tried the game without the camera and it still lags. Is this a Construct 3 issue that can't be fixed? Or is there a solution?

    I've already tried increasing and decreasing the cell size, deceleration, and rotation speed, but it's still the same.

    TL;DR: How do I optimize pathfinding behavior to make the game run faster?

    By the way, here's the link to the video game I made so you can try it yourself and see what I mean: construct.net/en/free-online-games/lethal-al-demo-80972/play

  • Hi.

    But how do you think we can understand the problem in the game without seeing the code?

    Perhaps you think that Construct3 has some mechanics that always cause problems, and we will tell you a life hack on how to get around it. But if there was such a problem that was common to everyone, the engine developers would have solved it long ago.

    I ran your demo, but there are only a few enemies, and they couldn't lower the frequency to the bottom.

  • construct.net/en/free-online-games/lava-gun-69421/play

    Once I posted such a demo, I didn't notice any terrible load on the system.

    After that, I made a 3D game for low-end smartphones, and everything is fine with performance there too.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Cool.. but how do you know it is the pathfinding behavior?

    Did you check via the debug panel to what's causing the lag?

    Did you test without any monsters?

    Does it happen frequently with more monsters?

  • Cool.. but how do you know it is the pathfinding behavior?

    I've tested it on several different video games I made. Most of them don't even have a 3D camera.

    Did you check via the debug panel to what's causing the lag?

    Yes, but it didn't give me a clear answer, it only showed me that the frames per second dropped drastically.

    Did you test without any monsters?

    Yes, I tested it twice without enemies, and it runs perfectly. No frame rate drops.

    Does it happen frequently with more monsters?

    Yes. The FPS drops almost instantly when you double the number of monsters. Probably because the PC struggles to calculate their paths.

  • Hi.

    But how do you think we can understand the problem in the game without seeing the code?

    I've attached the link to Construct Arcade, where you can download the source code. But if it doesn't open, you can download it from Mega: mega.nz/file/WKwWQSjK

    Perhaps you think that Construct3 has some mechanics that always cause problems, and we will tell you a life hack on how to get around it. But if there was such a problem that was common to everyone, the engine developers would have solved it long ago.

    Yes, that's more or less what I thought, but you're right, it's unrealistic.

    I ran your demo, but there are only a few enemies, and they couldn't lower the frequency to the bottom.

    Then the problem might be with my computer. I'll try it on another computer and let you know. Thank you very much.

  • I've attached the link to Construct Arcade, where you can download the source code. But if it doesn't open, you can download it from Mega: mega.nz/file/WKwWQSjK

    ...

    - Sorry, buddy, I didn't notice that you could download it there.

    - I ran a test and didn't notice any stuttering or frame rate drops. I recorded a video for you, you can check it out yourself.

    fex.net/en/s/x3tak4f

    - I looked through the code. There is room for optimization, and some actions can be performed only when necessary, rather than every tick. But there's nothing terrible about that.

    - I liked how you made the monster destruction and those pieces falling on the floor.

    - Maybe other guys will catch this problem on their PCs and investigate it.

  • On my PC, it definitely lags and sometimes freezes.

    In my opinion, this is where the issue comes from... You already are calling the "Find path" via a timer... then you call it again via "On failed to find path"... this creates a massive impact on performance.

    Disable "On failed to find path" then test it from your side. (Also... yeah your code can be optimised in so many ways...)

  • On my PC, it definitely lags and sometimes freezes.

    In my opinion, this is where the issue comes from... You already are calling the "Find path" via a timer... then you call it again via "On failed to find path"... this creates a massive impact on performance.

    Disable "On failed to find path" then test in from your side. (Also... yeah your code can be optimised in so many ways...)

    Thank you so much, it definitely works 👍.

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