Optimize Physics Collisions

0 favourites
  • 14 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • Hi there!

    I have a game that uses physics. Now, when my object is about to collide with another physics object (so before the collision has even taken place) the game lags ever so slightly.

    This has been happening for the last 20+ or so versions, and I'm not sure what's causing it. I'm using the Box2D web physics because I frequently disable and enable collisions between these objects.

    Additionally, I recall hearing about a certain order you need to run the collisions, but I don't recall fully understanding it at the time of reading, let alone now a few weeks/months down the line.

    I am assuming the slowdown is related to the collisions... it may be something else, but it is a bit odd that it will only slow down when it's approaching another object. If anyone has any clue how to help, I'd appreciate it.

    Because they are physics objects, they sort themselves out, I don't need to add anything in... However, upon collision, the objects have an instance variable that changes. That's about it.

  • I've just gone through the process of 'optimizing' my project, ensuring that 'on collision' commands are now the first condition at the top level events.

    My number of collision checks per tick have increased from 18 to 31. Will this still improve things somewhat, or have I just made my project slightly slower? I expected that number to lower, not increase.

  • I've just put a mobile physics game on hold because of this collision slowdown - I was planning to use CJS for android/ios but I found that the game hesitated on a collision for just a few ticks, as if the physics engine couldn't readily cope. I removed all events associated with collision triggers/tests to see the physics engine in action and it continued to happen - I now don't think I will be able to use physics for mobile (desktop was good, though).

    I also found that torque or impulse/force events gave different results depending on the mobile handset I tested on (S2, G1 and toshiba tablet - all different - I remember your previous force problem question). So not only was the game visually disappointing but the game play was different on each device. The same variations were apparent when trying over wifi on android chrome... Sorry - it's a bit of a whinge and not a solution to your problem AnD4D, but I can't think of a way to optimize further. Using the debugger, were any event groups showing a particularly large drain on CPU use - might be worth trying to focus on those..??

  • Use cocoonjs native collisions not box2d.

    Redice collision plygons.

    Never use web gl

  • Sorry - it's a bit of a whinge and not a solution to your problem AnD4D, but I can't think of a way to optimize further. Using the debugger, were any event groups showing a particularly large drain on CPU use - might be worth trying to focus on those..??

    Misery loves company, so it's all good

    Using the debugger, my highest usage are the events showing a 16% usage, and overall, I'm seeing a maximum of 36% usage (and that's on a busy level). This should indeed be fine, I believe.

    It's just frustrating to me, as I had this game finished back in November, so can't really put it on hold

    I'm mainly concerned now that my collision checks per tick have effectively doubled since doing the recommended optimization. To me, it makes more sense to put them at the bottom to ensure certain conditions are stripped out.

  • I'm actually having a similar problem. My game is all about physics. (Peggle style)

    I've stripped down as much as i could (to my knowledge)

    but im still getting bug reports from players having lagg issues on desktop.

    (i havent even decided to release it on IOS / android) it would simply not be possible.

    However im also interested in various optimization issues.

    (i am testing different things at the moment, so i'll be sure to get back if i figure out something)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How is this compared to yours?

  • xanxion

  • Can you upload the image on http://www.zippyshare.com/ instead?

    the image is not showing :/

  • Works now!

  • xanxion

    Just sent you a PM. Did you get it?

  • hmm weird, your optimization is not really working it looks like.

    Did you just rearange your events?

  • xanxion

    Yeah, I moved all of the collision events to the top most level as per the instructions. I have noticed a slight drop in the poly checks, but I was getting better results it seems from having them at the bottom. I notice you're getting a lot higher collision checks though, which is surprising.

  • I do wonder if the collision checks aren't as important in the latest version, and if it's the poly checks we should be more concerned with.

    It's just strange my game slows down when I get close to an edge or object.

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