Optimize Physics Collisions

Get help using Construct 2

Post » Fri Feb 21, 2014 9:00 pm

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.
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Sun Feb 23, 2014 1:40 am

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.
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Sun Feb 23, 2014 2:07 am

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..??
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,193

Post » Sun Feb 23, 2014 2:58 am

Use cocoonjs native collisions not box2d.
Redice collision plygons.
Never use web gl
B
12
S
4
G
1
Posts: 241
Reputation: 1,699

Post » Sun Feb 23, 2014 12:51 pm

Colludium wrote: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 :lol:

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 :cry:

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.
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Sun Feb 23, 2014 3:06 pm

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)
B
37
S
9
G
8
Posts: 541
Reputation: 8,554

Post » Sun Feb 23, 2014 3:08 pm

How is this compared to yours?

Image
B
37
S
9
G
8
Posts: 541
Reputation: 8,554

Post » Sun Feb 23, 2014 3:18 pm

@xanxion

Image
B
79
S
12
G
7
Posts: 961
Reputation: 10,717

Post » Sun Feb 23, 2014 3:34 pm

Can you upload the image on http://www.zippyshare.com/ instead?
the image is not showing :/
B
37
S
9
G
8
Posts: 541
Reputation: 8,554

Post » Sun Feb 23, 2014 3:35 pm

Works now!
B
37
S
9
G
8
Posts: 541
Reputation: 8,554

Next

Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 9 guests