Pyprocessing 3d collisions

in these lines

if self.cor.x - self.r <= 0 or self.cor.x + self.r >= width: self.vel.x = -self.vel.x
        

you treat left and right border in ONE line. In both situations you react with self.vel.x = -self.vel.x

This is common, even on the website. I don’t like it, since it can lead to brief stuttering.

Suggestion

Instead I separate this and use abs() (I don’t know if we have this abs() in python):

if self.cor.x - self.r <= 0: self.vel.x = abs(self.vel.x)

if self.cor.x + self.r >= width: self.vel.x = - abs(self.vel.x)
        

same for the other checks

(why do you increase / decrease z vel?)

Chrisir

2 Likes