Moving rogue body/space does not respond to collisions

Official forum for the Chipmunk2D Physics Library.
Post Reply
Ohmnivore
Posts: 2
Joined: Thu Aug 08, 2013 9:33 pm
Contact:

Moving rogue body/space does not respond to collisions

Post by Ohmnivore »

Well I'm using pymunk, the python wrapper around chipmunk. I'm having a hell of a time trying to make a moving platform. Here's the example I followed to make a moving platform.
http://pymunk.googlecode.com/svn-histor ... tformer.py

I mimic this in my code as follows:
Initiation of the moving platform:

Code: Select all

if x[2] == 2:
                platform.image = IMAGESDICT['MovingDanger']
                platform.initposx = platform.position_x
                platform.initposy = platform.position_y
                platform.lx = x[4]
                platform.ly = x[5]
                platform.sx = x[6]
                platform.sy = x[7]
                platform.ox = x[8]
                platform.oy = x[9]
                platform.xxx = 0
                platform.yyy = 0
                platform.bound = Rect(x[0], x[1], 168, 22)
                platform.body = pymunk.Body(pymunk.inf,pymunk.inf)
                platform.body.position = from_pygame(Vec2d(platform.position_x, platform.position_y), DISPLAYSURF)
                xp, yp = platform.bound.topleft
                width = platform.bound.width
                height = platform.bound.height
                platform.shape = pymunk.Poly(platform.body, [from_pygame(Vec2d(xp,yp), DISPLAYSURF),                      from_pygame(Vec2d(xp+width,yp), DISPLAYSURF), from_pygame(Vec2d(xp+width,yp+height), DISPLAYSURF), from_pygame(Vec2d(xp,yp+height), DISPLAYSURF)])
                platform.shape.friction = 2.4
                space.add(platform.shape)
                self.platforms.append(platform)
                self.movingplatforms.append(platform)
The shape and stuff are all correct. First off, this is pretty much the code I use for my static shapes, so it is doing what is expected.
Here is how I update the platform every step:

Code: Select all

    for platform in my_map.movingplatforms:
        oldpos = platform.body.position
        platform.body.position.x += platform.lx * math.sin(platform.sx * platform.xxx + platform.ox) #* dfps
        platform.body.position.y -= platform.ly * math.sin(platform.sy * platform.yyy + platform.oy)
        platform.body.velocity = platform.body.position - oldpos
        platform.yyy += 1
        platform.xxx += 1
I later on have a function to display the blocks at their positions. They are moving as expected, but fail to react to any collisions. The player can collide with all the other shapes in the space, except for the moving ones.
Here's a pastebin of my entire code: http://pastebin.com/KQJxWszC
Don't hesitate to point out obvious stuff, I'm a noob in regards to chipmunk. I just can't get my head around this problem! :cry:
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Moving rogue body/space does not respond to collisions

Post by viblo »

One thing I see in your code is that you dont divide the velocity with the delta time like the platformer.py example does. But im not sure if thats the only problem.. :)
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
Ohmnivore
Posts: 2
Joined: Thu Aug 08, 2013 9:33 pm
Contact:

Re: Moving rogue body/space does not respond to collisions

Post by Ohmnivore »

I added the delta time stuff, but it doesn't fix it.
Thanks anyways
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests