Box2D Forums

It is currently Fri May 24, 2013 1:08 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Jun 03, 2012 6:40 pm 
Offline

Joined: Sun Jun 03, 2012 6:26 pm
Posts: 1
I have a world in which I have some EdgeShape objects that I use to outline the border of my terrain, my terrain is quite large and currently uses 2464 EdgeShapes. I have added one DynamicBody (which I set as a box) to the world that I use as my character, I then use this character shape to navigate around my map.

The trouble is that performance is quite bad.

I do not know how the collision code is run and cannot seem to find any resources on the matter. I would specifically like to know a few things;

1 - Are all of the EdgeShape objects checking for collisions with other EdgeShape objects? I believe that this is not the case but I cannot be sure. I create the world with
Code:
world = new World(new Vector2(0,-10), true);
(Java)

2 - Is my player object calculating its collisions with all the EdgeShapes on the world (and mostly getting negative results). I believe that this is the case as performance is low and I have never told it not to check for collisions with only a selection of the objects.

I doubt that 1 is true but I think that 2 is correct, therefore my questions on optimisation are how can I only check for collisions with my player box and EdgeShapes that are close by (each edgeshape is only 1m long). And are edge shapes the correct class to be using for my terrain in the first place?

Performance problems occur on Android btw.


Top
 Profile  
 
PostPosted: Sun Jun 03, 2012 8:35 pm 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
2464 is quite a lot, static or dynamic. x]

First off, are you sure that it's the physics engine that's causing the lag and not the graphics rendering?

Secondly, are all of the edge shapes in one body (or in several bodies, as long as it's not one body per edge shape)? If you already have the edge shapes in one body, try separating each section of the map/world into several bodies. I'm not sure if that will help. But definitely do not have one body per edge shape.

Edge shapes or any static body should not be checking each other's collisions. Have you tried running the game without the dynamic body? If so, does it still have lag without the dynamic body?

You can set bodies as inactive (body.SetActive()) when they're not nearby. Setting them as inactive will skip calculations for those bodies (though having to check every frame if the edge shape bodies are nearby may still generate some lag).

Here is more information about how collision works in Box2D: http://www.iforce2d.net/b2dtut/collision-anatomy


Top
 Profile  
 
PostPosted: Wed Jun 20, 2012 9:07 am 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2931
Edge shapes never collide with each other. Also one small object should not collide with all edges at once. Box2D has a broad-phase that quickly culls impossible collisions.

You will get better performance using chain shapes. As jayther points out, using a small number of bodies will help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group