Moving rogue body/space does not respond to collisions
Posted: Thu Aug 08, 2013 9:49 pm
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:
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: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!
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)
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
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!
