Slow Simulation Problems; Other Strange Effects

Discuss issues specific the Python port of Box2D
KillaChaos
Posts: 2
Joined: Sun Dec 13, 2009 4:11 pm

Slow Simulation Problems; Other Strange Effects

Postby KillaChaos » Sun Dec 13, 2009 4:33 pm

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()

BorisTheBrave
Posts: 1911
Joined: Mon Jan 07, 2008 10:51 am
Contact:

Re: Slow Simulation Problems; Other Strange Effects

Postby BorisTheBrave » Tue Dec 15, 2009 3:44 pm

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++).

KillaChaos
Posts: 2
Joined: Sun Dec 13, 2009 4:11 pm

Re: Slow Simulation Problems; Other Strange Effects

Postby KillaChaos » Wed Dec 16, 2009 4:21 pm

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.

shadiq
Posts: 5
Joined: Sun Jun 05, 2011 9:55 am

Re: Slow Simulation Problems; Other Strange Effects

Postby shadiq » Mon Jun 27, 2011 8:05 am

No more to say the strength of this program.


Return to “Python”



Who is online

Users browsing this forum: No registered users and 1 guest