I'm quite new to Pico-8 and video game programming and so started out by making a simple ping pong like game. I can't seem to figure out how to make my ball collide with the side of the paddle however which leads to the ball getting stuck inside the paddle, bouncing up and down, or just passing through the paddle.

Ideally I'd like the ball's x and y velocity to reverse when it hits the sides of the paddle.

Thanks in advance for any help!

'p' is my paddle object

'b' is my ball object

p.w is the paddle width

p.h is the paddle height

--ball wall collision if b.x>=128 then b.dx*=-1 end if b.x<=0 then b.dx*=-1 end --ball paddle collision top if b.x>=p.x and b.x<=p.x+p.w and flr(b.y)==p.y-b.size then b.dy*=-1 end |

Have you looked at the first issue of the PICOZINE? There is a squash ball-paddle example in there which should help a bit.

In addition, you probably want to check if the b.y is somewhere between p.y and p.y+p.h, as well as b.x > p.x and b.x < p.x+p.w.

[Please log in to post a comment]