Assignment operator

I was preparing simple animation game of bouncing ball.
There I have to insert an assignment condition for collision with a paddle to bounce.
But it seems that p5js isn’t compatible with assignment operator.
Its not assigning. The program stops when run on browser.

Please give me any solution to this problem.

here is that assignment statement:

(ball.yCor+rad == pad.yPaddle)
1 Like

possibly a little example
helps too.

1 Like

Thanks for reply. I do made changes but still why you didn’t used ‘==’ operator to check ball’s collision with the paddle?

just think what would happen if you use float numbers, and

ballyCor + rad == 12.0000001

padyPaddle == 12

it would be too late to stop it ( using == ).
so better check for overrange and reset it hard.

ballyCor = padyPaddle - rad;

later you might be using variable speed in your position calculation.

1 Like