physics - is there a limit to the number of physical bodies the api can handle

Hi I’ve been building an app in my spare time for a while now but this is my first post.

Is there a limit to the number of physical bodies I can add to the physics api?

Here’s the situation.

I’m building a game can have multiple physical bodies on the screen at a time.

in particular I have one level where there are 55 physical objects on the screen.
I also have a transition scrolling an image across the screen in the background.

I do not notice a slowdown in the simulator.

I notice a slowdown occurring with the physical objects, but not with the transition on my test device (iPhone 4).

At this time Textured Memory = 17Mb
and System Memory = 0.43Mb

Thank you,

Paul

[import]uid: 179920 topic_id: 31654 reply_id: 331654[/import]

Hi Paul,

There’s no limit to the number of bodies you can create imposed on the software side of things. However, as you add more bodies, you’ll eventually hit a hardware limitation, in that the amount of processing time required to simulate all of the bodies will be longer then the length of a frame. At that point you’ll see a drop in the frame rate (which it sounds like you may already have encountered). When this happens will vary for each specific device, since it depends on the speed of the hardware.

To reduce processing time, and therefore enable you to simulate more bodies, you can do a few things:

  • Make sure your bodies aren’t tagged as bullets unless necessary
  • Set continuous physics to false ([lua]physics.setContinuous(false)[/lua])
  • Don’t set the position and velocity iterations too high unless necessary
  • Don’t create lots of joints unless necessary. In particular, instead of weld joints, use a complex physics body

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 31654 reply_id: 126424[/import]

This really depends on the device more than anything else; it might run fine on a iPhone5 but horrendously on a 3GS. One of those times it’s best to test on a number of devices. Android I would suspect you would likely get some slow down on lower end armv7 devices. [import]uid: 52491 topic_id: 31654 reply_id: 126426[/import]

Thank you, Andrew and Peach for your quick replies.

Very much appreciated!
[import]uid: 179920 topic_id: 31654 reply_id: 126432[/import]

I didn’t see Andrew’s reply when I was writing mine, oops! Very thorough :slight_smile: [import]uid: 52491 topic_id: 31654 reply_id: 126594[/import]

Hi Paul,

There’s no limit to the number of bodies you can create imposed on the software side of things. However, as you add more bodies, you’ll eventually hit a hardware limitation, in that the amount of processing time required to simulate all of the bodies will be longer then the length of a frame. At that point you’ll see a drop in the frame rate (which it sounds like you may already have encountered). When this happens will vary for each specific device, since it depends on the speed of the hardware.

To reduce processing time, and therefore enable you to simulate more bodies, you can do a few things:

  • Make sure your bodies aren’t tagged as bullets unless necessary
  • Set continuous physics to false ([lua]physics.setContinuous(false)[/lua])
  • Don’t set the position and velocity iterations too high unless necessary
  • Don’t create lots of joints unless necessary. In particular, instead of weld joints, use a complex physics body

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 31654 reply_id: 126424[/import]

This really depends on the device more than anything else; it might run fine on a iPhone5 but horrendously on a 3GS. One of those times it’s best to test on a number of devices. Android I would suspect you would likely get some slow down on lower end armv7 devices. [import]uid: 52491 topic_id: 31654 reply_id: 126426[/import]

Thank you, Andrew and Peach for your quick replies.

Very much appreciated!
[import]uid: 179920 topic_id: 31654 reply_id: 126432[/import]

I didn’t see Andrew’s reply when I was writing mine, oops! Very thorough :slight_smile: [import]uid: 52491 topic_id: 31654 reply_id: 126594[/import]