Box2D Forums

It is currently Wed Oct 01, 2014 9:21 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Dec 13, 2009 4:33 pm 
Offline

Joined: Sun Dec 13, 2009 4:11 pm
Posts: 2
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:
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:
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()


Top
 Profile  
 
PostPosted: Tue Dec 15, 2009 3:44 pm 
Offline

Joined: Mon Jan 07, 2008 10:51 am
Posts: 1911
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++).


Top
 Profile  
 
PostPosted: Wed Dec 16, 2009 4:21 pm 
Offline

Joined: Sun Dec 13, 2009 4:11 pm
Posts: 2
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.


Top
 Profile  
 
PostPosted: Mon Jun 27, 2011 8:05 am 
Offline

Joined: Sun Jun 05, 2011 9:55 am
Posts: 5
No more to say the strength of this program.


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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