Box2D Forums

It is currently Wed May 22, 2013 9:33 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Mar 06, 2012 12:24 am 
Offline

Joined: Tue Mar 06, 2012 12:07 am
Posts: 2
Hi everybody,

I'm making a game in Actionscript 3 where there can up to about 350 small square objects (all the same size, with fixed rotation) that move and can collide with each other. I don't really need the physics part of Box2D, my real problem is making sure that objects don't overlap. I tried making my own algorithm, but this is difficult because in my game objects can spawn anywhere, so it needs to work well in separating objects when they're all clumped together and objects can be created in the middle of them.

I also need that when an object collides with another, that it doesn't "push" it. For example, if an object collides straight on with a stationary (but dynamic) object, the stationary object should remain in the same position, while the object that collided with it stops. So basically the only way for an object to move would be for me to move it directly with SetLinearVelocity().

I already tried out Box2D, but unfortunately the performance isn't quite as good as I need (even with only 1 velocity and position iteration), and I can't find a way for the objects to react (or "not react") as I need.

Is there anything I can do to make the performance better, and make objects not "push" each other (unless to remove them from a collision of course)? If not, is there another collision engine I should be looking into, or perhaps an algorithm I can learn and try to implement?

Thanks in advance!


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 4:04 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
The 'un-pushable' body you are talking about sounds exactly like a kinematic body... search for 'kinematic' in the manual.

About performance, this really depends on the hardware and to some extent the port you're using. For example on iPhone3GS, about 200 bodies seems to be the most you could expect to have with reasonable performance in a typical scene, while the C++ version on a regular PC should have no problem with thousands of bodies. 350 seems kinda low, is that for PC or some kind of mobile device?


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 4:24 am 
Offline

Joined: Tue Mar 06, 2012 12:07 am
Posts: 2
I did try using kinematic bodies, but they don't collide with each other at all... they go right through each other.

I'm using the Actionscript 3 port. I get about 40 FPS with 350 objects, but since my PC is relatively fast I need it to perform a bit better to run on slower machines.


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 5:37 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
That's right, kinematics do not collide with each other, so "basically the only way for an object to move would be for me to move it directly with SetLinearVelocity()" ;)
It sounds like you will need to program in a bit more customization somewhere for what you are trying to do. One possibility is for each dynamic body to have a kinematic body 'shadowing' its movements, and set the collision filter of the kinematic fixture so that it collides with the other dynamic bodies. iirc I tried this and posted an example to the forum here, perhaps you could try to find that. I think it worked ok for simple cases.


Top
 Profile  
 
PostPosted: Tue Mar 06, 2012 5:41 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
viewtopic.php?f=3&t=7897&p=34145


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 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