Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

weird physics bug when a ball hits the left wall

for some reason when a ball hits the left wall it gains momentum

i tried using "* -1" instead of "-"

heres the code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


y = y + vel_y
x = x + vel_x
vel_y = vel_y + 1
if y >= 900:
    y = 900
    vel_y = -(vel_y - 10)
if x >= 900:
    x = 900
    vel_x = -(vel_x - 10)
if y <= 100:
    y = 100
    vel_y = -(vel_y - 10)
if x <= 100:
    x = 100
    vel_x = -(vel_x - 10)

im using python and pygame

>Solution :

Since vel_x is negative when going left, the calculation -(-vel_x - 10) gives vel_x + 10, which will be bigger than the velocity before you hit the wall. Say the initial velocity is -50, you get -(-50 - 10) = 50 + 10 = 60. Make sure subtraction of the speed reduction makes sense.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading