Help implementing performance increasing method for collsion

0 favourites
  • 9 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • I think I have come up with a way to increase performance with collision checks, but need some help to implement it OR if it works only by checking all instances simultaneouly, I would like to know that as well anyway.

    So, what I want to acheive is, check collisions per instance (unit/object) against all other map objects/instances but, add a specified time (variable) between checking collisons for each instance.

    For example: tick 1; instance 1 checks for collisions. tick 2; instance 2 checks for collsions. tick 3; instance 3 checks for collisions.. reapeat X amount of times, X = amount of instances on map. Currently I beleive the collision checks happen for all instances per tick or per X seconds (if set).

    Once the above is implemented, I'll then add this: If the amount of instances is greater than (variable) OR alternatively the total time required to check for collsions (variable) has passed variable amount, then add next instance to tick 1/first collision check.

    For example: instance no. 25 is set to check on tick 25, however, instance 26 is then set to check on tick 1, repeat until no more new instances are available to check.

    Currently the amount of instances on the map (> 400) reduces fps considerably, I hope to get it up to 2000.

  • 400 instances shouldn't cause a slowdown. I'd say neither should 2000- unless using lots of effects, etc.

    Can you provide a small rough prototype .capx that shows your problem?

    Test your spec:http://www.scirra.com/demos/c2/sbperftest/

  • You can also run your game in Debug Mode and check the actual number of collision checks.

    C2 games can run smoothly even with thousands collision checks performed every tick.

  • I was unsure on how to attach a file via a post and so I have uploaded it to dropbox: "https://www.dropbox.com/s/32sne694ovk6cvg/Collision%20Detect.capx?dl=0"

    To use, Middle click to spawn units. Right-Click to tell units to pathfind to the current mouse location. Up, Down, Left, Right for camera, Middle-Scroll Up/Down to increase/decrease timer for collision checking.

    When spawning more than 400, I start to see an FPS drop when pathfinding.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you really need to check for collisions between all 2000 instances? Cause that's millions of checks every tick, and I don't think any optimizations will help in this extreme case..

    I made some changes to your file, have a look:

    https://www.dropbox.com/s/q0im3vciif8u2 ... .capx?dl=0

    You should only use "Is Overlapping" with this method, don't use "On collision".

    And, of course, the more objects are added, the less often overlapping checks are performed for each of them, so the accuracy of collision detection will decrease.

    Also, interestingly, when instances are spread on the layout, the number of collision checks is lower, than when all instances are in one spot. I'm guessing the engine is skipping unnecessary checks for objects that are too far away from each other.

  • 1.) Those changes are very helpful and have increased performance dramatically, thank you. However, on overlapping rather than behaving as solid, when I change the units to divide their distance equally within their group, is that going to stop other units in other groups from crossing individual units within the first group?

    2.) The collsion checks don't need to be checked for every instance on the map, providing collision isn't an impassable (cliff/building) and would prevent pathfinding to detect it which would cause units to either go over/through it (with overlapping) or go to it and then need to recalculate pathfinding to go around it, which would look horrible and be inefficient.

    3.) Although your solution works well, is my original method feasable? And if it is, I'm sure it could combind it with your solution.

    How did you learn about the skipping unnecessary checks?

  • Also, interestingly, when instances are spread on the layout, the number of collision checks is lower, than when all instances are in one spot. I'm guessing the engine is skipping unnecessary checks for objects that are too far away from each other.

    That would be Collision Cells

    https://www.scirra.com/blog/ashley/6/co ... on-in-r155

  • 1.) Those changes are very helpful and have increased performance dramatically, thank you. However, on overlapping rather than behaving as solid, when I change the units to divide their distance equally within their group, is that going to stop other units in other groups from crossing individual units within the first group?

    2.) The collsion checks don't need to be checked for every instance on the map, providing collision isn't an impassable (cliff/building) and would prevent pathfinding to detect it which would cause units to either go over/through it (with overlapping) or go to it and then need to recalculate pathfinding to go around it, which would look horrible and be inefficient.

    Sorry, I read these questions multiple times, but still don't understand them.

    Could you explain what all these triangle objects will be doing in your game? And why do you need to check if they collide with each other.

    3.) Although your solution works well, is my original method feasable? And if it is, I'm sure it could combind it with your solution.

    How did you learn about the skipping unnecessary checks?

    My solution is basically the same as your method. On tick 1 collision is checked for the first 20 instances. On tick 2 - for the next 20 instances. And so on.

    Run the project in Debug Mode. You'll see the number of collision checks is much lower when instances are spread and increases when they all move to the same point.

  • So for question one, your method is basically saying, for every 20 instances, put them in a group that acts as one (collision-wise). Since this is true, imagine if each group of 20 was spread out in a small area which would show as if they were not overlapping. Then, would another group of 20 individual instances (called group 2), individually collide with the first groups instances individually. Or in other words, would any one instance within group 1 collide with any one instance within group 2, that is if I then told them to move away from each other on overlap (similar effect to a solid behavior). If it does, your solution will work for my game.

    Well, each instance is controllable individually, if the instances within a group are overlapping, the player cannot specifically and individually select an instance within a group to give it a command.

    I accidentally overlooked a part of the code you implemented "currentGroup>=int(BoxFamily.Count/groupSize) ? 0 : currentGroup+1", sorry!

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