Page 1 of 1

Slow Simulation Problems; Other Strange Effects

Posted: Sun Dec 13, 2009 4:33 pm
by KillaChaos
I am using pyBox2d and I have a problem with the speed of the simulation. I am trying to make a platformer-esque game and everything seems painfully slow. I am drawing with pygame, and running at a full 60 frames per second. However applying an impulse of 1000000000 does not seem to increase the speed of the object. Also, applying an impulse of (largenumber, 0), seems to negate gravity. (For example, if the character is in mid air, and "Left" is pressed, the character just slides leftward, but glides instead of falls)

Here is my code:

Code: Select all

worldAABB=box2d.b2AABB()
worldAABB.lowerBound = (-10000, -10000)
worldAABB.upperBound = (10000, 10000)

world = box2d.b2World(worldAABB, (0,-900), True)
...
#def __init__(self, world, w, h, mass = 0, friction = 0, x=0, y=0):
main = display.Sprite(world, 50, 100, 1, 0, .1, 600)
ground = display.Sprite(world, 5000, 600, 0, 0, 0, 0)
...
while running:
...
    if keys[pygame.K_LEFT]:
        main.body.ApplyImpulse( (-1000000000,0),main.pos() )
    if keys[pygame.K_RIGHT]:
        main.body.ApplyImpulse( (1000000000,0),main.pos() )
    if keys[pygame.K_UP]:
        main.body.ApplyImpulse( (0,1000000000),main.pos() )
    if keys[pygame.K_DOWN]:
        main.body.ApplyImpulse( (0,-1000000000),main.pos() )


Sprite class:

Code: Select all

class Sprite(object):
    inertia = None
    body = None
    shape = None
    sprite = None
    mass = 0
    size = (0,0)
    static = False
    color = (255,0,0)
    surface_height = 0

    def __init__(self, world, w, h, mass = 0, friction = 0, x=0, y=0):
        bodyDef = box2d.b2BodyDef()
        bodyDef.position = (x,y)
        self.body = world.CreateBody(bodyDef)
        shapeDef = box2d.b2PolygonDef()
        shapeDef.SetAsBox(w/2.0, h/2.0)
        shapeDef.density = float(mass) / (w*h)
        shapeDef.friction = friction
        self.shape = self.body.CreateShape(shapeDef)
        self.body.SetMassFromShapes()

Re: Slow Simulation Problems; Other Strange Effects

Posted: Tue Dec 15, 2009 3:44 pm
by BorisTheBrave
Are you scaling your objects to be about .1 - 10 in size. Seems like you are hitting the upper velocity limit for objects (which is hard coded into the C++).

Re: Slow Simulation Problems; Other Strange Effects

Posted: Wed Dec 16, 2009 4:21 pm
by KillaChaos
BorisTheBrave wrote:Are you scaling your objects to be about .1 - 10 in size. Seems like you are hitting the upper velocity limit for objects (which is hard coded into the C++).


That was the problem. Thanks.

Re: Slow Simulation Problems; Other Strange Effects

Posted: Mon Jun 27, 2011 8:05 am
by shadiq
No more to say the strength of this program.