Code: Select all
def __init__(self, image, position, world, mass=1):
self.mass = mass
self.radius = 16
self.inertia = pymunk.moment_for_circle(self.mass, 0, self.radius)
self.body = pymunk.Body(self.mass, self.inertia)
self.body.position = self.position[0], self.position[1]
self.shape = pymunk.Circle(self.body, self.radius)
self.world.space.add(self.body, self.shape)
self.controlBody = pymunk.Body(pymunk.inf, pymunk.inf)
self.joint = pymunk.PivotJoint(self.body, self.controlBody, (0,0), (0,0))
self.joint.max_force = 10000
self.joint.bias_coef = 0
world.space.add(self.joint)
Code: Select all
def Move(self, velocity):
self.body.apply_impulse((velocity[0], velocity[1]))
self.position = [self.body.position.x, self.body.position.y]
self.rect.topleft = (int(self.position[0]), int(self.position[1]))
What i've noticed is that on collision the player and monsters always overlaps. When i move the player into the monster on purpose, they can overlap up to 90% but otherwise they always overlap around 25%.
Also, when the player and monsters clump together (currently the monsters are programmed to follow the player) and i move the player around, monsters frequently "jump" backwards, sometimes quite far and they slowly proceed to move towards the player again.
If I understand it properly, because collision is calculated after the move, the impulse makes the monsters constantly overlap the player and walls and other monsters.
I'm not after perfect circle to circle collision detection but how can i reduce these overlaps to say under 5% of the circle surface?
UPDATE:
I was able to setup some crude collision callback which stopped the monster on contact with the player. However this feels really unnatural because i'm manually creating a callback handler for something which i want the physics engine to deal with. I don't want to be manually positioning the monster whenever i detect an overlap with another object. Or am I thinking about this the wrong way?