Skip to content Skip to sidebar Skip to footer

How Can I Collide With A 45 Degree Slope?

I have spent the past 3 days trying to understand this but with every article I have read and every youtube video I have watched I have failed to comprehend the concept. I have giv

Solution 1:

Calculate the height of the diagonal rectangle on the right edge of the moving rectangle (my_rect.right):

dia_height = D_rect.height * (my_rect.right-D_rect.left) / D_rect.width

Compute the top of the the diagonal rectangle on the right edge of the moving rectangle:

D_rect_top = D_rect.bottom - round(dia_height)

The top of the the diagonal rectangle on the right edge of the moving rectangle is the bottom of the moving rectangle:

my_rect.bottom = D_rect_top

If the diagonal is in the opposite direction, find the height of the diagonal on the left edge (my_rect.left) instead of the right edge (my_rect.right).

The formula y = mx + b is hidden in this code:

x is my_rect.right - D_rect.leftm is -D_rect.height / D_rect.widthb is D_rect.bottomy is my_rect.bottom


whileTrue:
    # [...]if my_rect.colliderect(D_rect):
        dia_height = D_rect.height * (my_rect.right-D_rect.left) / D_rect.width
        D_rect_top = D_rect.bottom - round(dia_height)
        my_rect.bottom = D_rect_top

    # [....]

Post a Comment for "How Can I Collide With A 45 Degree Slope?"