Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Having trouble with Physics in Breakout game.

Author
Message
gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 29th Sep 2016 22:13
So I decided to do a Breakout game for practice.

At first I went with what I knew, moving everything using X and Y coordinates, but the problem here is that the ball will always follow the same path. The only challenge for the player is to catch the ball. I remember playing Breakout games where you could affect the angle of the ball depending how and where it hit on the paddle, so I tried to use physics.



I am still figuring them out but so far the problems are that often times the ball will roll on the paddle rather than bounce off and it refuses to bounce off the walls anymore.



If anyone could assist me in getting the ball to bounce correctly, help in controlling the velocity, and explaining these things, I would very much appreciate it.

-gameangel147

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Oct 2016 17:14
Changing the angle of the ball

When the ball hits dead center of the paddle, the ball goes straight up. We'll say this is at 0 degrees. Now let's decide at what angle the ball should bounce off the paddle when it hits the very edge of the paddle. Say, 65 degrees for example. When the ball hits the paddle, it will reflect at anywhere from -65 to 65 degrees, with 0 being the middle of course.

P = paddle position (center)
B = ball position
L = Half paddle length (40)
X = x-coordinate of ball when it hits the paddle, local to the paddle. So if your paddle is 80px, (again 0 being the middle) then the ball is between -40 and 40.
A = max reflection angle (65)
R = reflection angle of ball coming off paddle

X = B.x - P.x
R = X / A


Honestly, I'd skip the built in physics for a breakout game, I think it just over-complicates things. The physics for this type of game are simple enough to code yourself. Hit a wall? Just inverse one component of the ball's velocity. Same thing when it hits a brick, once you determine which side of the brick was hit (top/bottom or left/right).

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
gameangel147
11
Years of Service
User Offline
Joined: 2nd Dec 2012
Location:
Posted: 11th Oct 2016 21:24 Edited at: 11th Oct 2016 21:24
Wow, it seems so simple once it's written out.

Thank you so much Phaelax!!!

So are the built-in physics well made? Should I ever use them or should I just try to create my own physics, because I really like scripting with AppGameKit, but then something like Gamemaker has easier to use built-in physics.

For example if I wanted a ball to bounce off a circle, should I use physics or make my own?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Oct 2016 22:04
There's nothing wrong with AGK's physics, which I believe is Box2D (someone correct me if I'm wrong). I used them for an angry birds type game. But for something with very basic physics like breakout or pong or even a simple side-scroller (mario), I think it's overkill and more complex than you need.

Quote: "For example if I wanted a ball to bounce off a circle, should I use physics or make my own?"

Use physics for this one. Trust me, proper collision detection and response with spherical collisions isn't as simple as you'd think. We set a billiards (snooker) code challenge once in DBP. It ended up as a team effort in the end, so that should tell you something. It's fun to try if you want to tackle the math, I'm sure I can point to a few sources.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-21 21:11:17
Your offset time is: 2024-11-21 21:11:17