Hello everyone!
I'm currently working on trying to replicate Pong to learn how Löve2D/Lua works and I think I've come to the point where I want the ball in my game to bounce around. As you can see in the gif that I've attached that the Ball just moves to the left and doesn't bounce back against the Paddle.
I think that I've managed to break down on how the Ball works (which you can find in "Ball Behaviour.rtf") but I would like to start with the Ball at least bounce back against the Paddle.
And because I'm trying to learn Löve2D/lua I would appreciate if you could give me hints on it could be done without revealing to much.
I have also attached my project if you want to view what I'm doing.
Thanks!
Help: Advice on how to make my ball in Pong project "bounce"
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Help: Advice on how to make my ball in Pong project "bounce"
- Attachments
-
- Pong.zip
- (4.1 KiB) Downloaded 52 times
-
- Ball Behaviour.rtf
- (1.59 KiB) Downloaded 53 times
Have a good day!
Re: Help: Advice on how to make my ball in Pong project "bounce"
That's the field of collision and response. You need to detect collision and issue appropriate response action. You could use existing physics libraries for that, or do all the math yourself.
- Jasoco
- Inner party member
- Posts: 3725
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Help: Advice on how to make my ball in Pong project "bounce"
Look into Bump. It'll make it easier.
Otherwise you'll have to do the math yourself. A bunch of if checks on the position of the ball and the paddle.
Otherwise you'll have to do the math yourself. A bunch of if checks on the position of the ball and the paddle.
Re: Help: Advice on how to make my ball in Pong project "bounce"
The math shouldn't be all that much trouble, really. We can assume the ball only collides with the right edge of the paddle, so if the ball's x-velocity is negative (it's traveling left), and the ball's position is close enough to the paddle's position that they overlap, it should bounce.
To determine if two objects are close enough to overlap, you just need to compare the distance between their centers to their sizes. For example, if two circles each have a radius of 2 units and their centers are 3 units apart, they overlap.
To make the ball bounce you can just reverse its x-velocity (multiply it by -1).
To determine if two objects are close enough to overlap, you just need to compare the distance between their centers to their sizes. For example, if two circles each have a radius of 2 units and their centers are 3 units apart, they overlap.
To make the ball bounce you can just reverse its x-velocity (multiply it by -1).
Re: Help: Advice on how to make my ball in Pong project "bounce"
I'll take a look at Bump but right now I think my problem is to know when my ball and paddle collide with eachother.
I'm thinking something like "if ball image collides with paddle image then do this".
Have a good day!
Re: Help: Advice on how to make my ball in Pong project "bounce"
Yeah I figured that collision detection will be the problem and Jasoco recommended that I look up Bump.
I feel that I would like to do the math myself but as I mentioned I need to know when my two "objects" collide with each other..
Have a good day!
Re: Help: Advice on how to make my ball in Pong project "bounce"
As I mentioned about 20 minutes ago, they collide when they're close enough to overlap. If your paddle is 5 units from its center to its edge, and the ball's radius is 8 units, then any distance along x of 13 or less means they overlap along x. Do the same for y, if they overlap along both x and y then their AABBs overlap and you can consider them to be colliding (except you probably only want to do this when the ball is traveling left so it won't get stuck in the paddle).
Re: Help: Advice on how to make my ball in Pong project "bounce"
Thinking of everything that goes on in the computer as mathematical formulas will get you across much faster. Don't try to solve your problem in XYZ way, solve it mathematically. Grab a whiteboard and write down some equations, then punch them into your program.
Who is online
Users browsing this forum: Bing [Bot] and 84 guests