i tried to apply collisions to a squared object
def collision(self,obj):
d = obj.sprite_size * obj.scale + self.sprite_sizeself.scale/2
d2 = obj.sprite_size * obj.scale - self.sprite_sizeself.scale/2
dx = obj.position[0] - self.position[0]
dy = obj.position[1] - self.position[1]
if dx > -d and dx < 0 and abs(dy) < d2:
obj.position[0] = self.position[0] - d
elif dx > 0 and dx < d2 and abs(dy) < d2:
obj.position[0] = self.position[0] + d2
if dy > 0 and dy < d2 and abs(dx) < d2:
obj.position[1] = self.position[1] + d2
elif dy < 0 and dy > -d and abs(dx) < d2:
obj.position[1] = self.position[1] - d
it works fine except the part where i collide the object by moving from below it. it still applies but for some reason the x statement also applies and glitches me to the left.
this doesnt apply if i do the same y issue from above it.
the pivot of both objects are on the top left