#๐Ÿ”’ collision detection

4 messages ยท Page 1 of 1 (latest)

whole peak
#

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_size
self.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

elfin bladeBOT
#

@whole peak

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

elfin bladeBOT
#

@whole peak

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.