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 DBPro Corner / Bouncing Ball

Author
Message
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 3rd May 2004 14:25
Hi

I've been trying to find out the mathematical calculation for calculating the movement of a ball that rebounds. e.g. in a Pong type game on how the ball rebounds of the bat at various angles dependant on the angle of attack and the way the player moves. Also, in games such as breakout on how the ball bounces off of walls.

I'm looking to do it in a 2D environment so therefor it must add/subtract to X and Y coordinates and not use a rotate command.

I've done a very simple version but it only works with 45 degree angles and its all using flags i.e. 8 flags each representing a + or - to X and Y dependant on direction.

Please please help....this has been puzzling me for ages.
Cyberflame
21
Years of Service
User Offline
Joined: 4th Sep 2003
Location: Im not sure....
Posted: 3rd May 2004 14:36
Look at the 3d pong game tut..while it may not be 100% accurate (or is it?) it does work.

DANGIT NEO, YOU CHANGED THE CODE AND NOW THE MATRIX WONT TEXTURE RIGHT.
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 3rd May 2004 19:54
Thanks Cyberflame, but the 3d pong tutorial in the stickies uses rotate and angles which wont work in a DBC program if you want to use 2D like I do(would in DB Pro as you can rotate sprites too and use move with it).

What I need to do is work out a program which basically takes the angle that is calculated using some kind of equation (this I need to know) and then work out how to move the ball on that angle by either adding or subracting values from the X and Y positions....

Any ideas???
Evilcatt09
21
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 4th May 2004 03:19
if the ball is bouncing up and down just test to see if the ball has touched the bottom edge and if it has multiply the y speed by -1 to change the direction, this should make it look like its boucing.

I have the coolest signature, here it is...
I have the coolest signature, here it is...
comando 300
21
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 4th May 2004 03:43 Edited at: 4th May 2004 03:47
a little code



CURRENT PROJECT: RETRO PAC-MAN
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 4th May 2004 03:43
Thanks Evilcatt....

I'm looking to make the ball bounce around the screen though, as in the game Breakout/Arkanoid, or a game of Snooker....
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 4th May 2004 03:44
Thanks also commando....

presume thats just for bouncing up and down though looking at the code.....thanks anyway.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 4th May 2004 16:04 Edited at: 4th May 2004 16:05
evilcatts answer and commando's code will do what you want.
Have a xvelocity and a yvelocity then just reverse yvelocity when it hits top or bottom and xvelocity when it hits left or right.
After you done your basic engine you can take into account movement of the bat backspin etc but to start with just use reverse velocity method.

I did this in DBpro - should work in classic:




Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 5th May 2004 03:13
Thanks again for the comments.....but all this I have done numerous times. What I am actually looking for is the mathematical calculation that will reposition the object (ball) so that it travels along a particular vertices (think that's the right word...a line from a to b) so in effect it looks as though a ball would when playing a game such as snooker or pool. i.e. if you hit it at an angle of 36 degrees (for example) up the table towards a side, it will rebound in the correct manner off of the side of the table.

Using methods that were forementioned generates a very square effect (very un-natrual) as it will generally only move on 45 degree angles giving a possibility of only 8 vertices it can travel along which isnt true to a game such as snooker.....

any ideas anyone that comply with this?
Social Disease
21
Years of Service
User Offline
Joined: 30th Sep 2003
Location: State of Confusion, beyond Denial...
Posted: 6th May 2004 12:06
If you imagine the ball's path as being a line, you need to find the angle it intersects the wall at.

If it intersects the wall at a 45 degree angle, it will leave at a 45 degree angle, if it hits at a 10 degree angle it will leave at a 10 degree angle. You will also have to take into account that the ball (in snooker, or pool as we call it on this side of the pond,) has velocity, and a great deal of that can be absorbed by the wall it hits, depending on the angle.

Also if you want to get truly complex, the ball can have different spins that can make the equation more of a parabola than a straight angle. your best bet is probably to get a marble and a shoe box lid or something, make some measurements, try a few things out, then think about it a whole lot.

Maybe this isn't very helpful, but I'm not a math whiz or a physics whiz, so if anybody is, feel free to correct me.

Think Gad fro Spill Chock!
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 8th May 2004 04:15
Thanks Social Disease....

Wouldnt have thought such a mathematical formula would be so hard to come across....I've been searching the net for ages.
Pixle Pusher
20
Years of Service
User Offline
Joined: 4th May 2004
Location: Monitor, Keyboard, Mouse. UK
Posted: 8th May 2004 15:12
Hi Gav_b_uk, Found this in the codebase, it might prove useful.
Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 8th May 2004 22:07
Thanks....looks as though it will be....
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 8th May 2004 22:51
You can use the same code as in my tutorial.

The object doesn't need to be rotated by the angle, you can still use it to calculate distances using newxvalue etc.

Doing it my way means the ball moves the same distance each sync.

DK_
20
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 9th May 2004 07:05 Edited at: 9th May 2004 07:07
just make an image of a ball and make it a sprite.

sprite 1,xpos,ypos,imageOfTheBall

this will allow you to use the rotate command and collisions in a 2D environment. For a game of pong I would just make images of the paddles the ball and the walls(for the boundaris of the ball) and set them to sprites. use the "move sprite" command and the "sprite collision" command. If a collision is detected, to get it to bounce use this code:



Gav_b_uk
20
Years of Service
User Offline
Joined: 18th Mar 2004
Location: Midlands, UK
Posted: 9th May 2004 16:05
Hi Phoenix....

Thanks for that....already thought of that though. Dont want to do it that way as I want to use it in DBC aswell as DBPro...also looking so I can use the calculation in the future within C++.

Thanks anyway
walaber
21
Years of Service
User Offline
Joined: 22nd Oct 2003
Location: Los Angeles, CA
Posted: 11th May 2004 13:15 Edited at: 11th May 2004 13:16
simple ball physics demo from the codebase:

http://www.thegamecreators.com/?m=codebase_view&i=67a4662b8f43893259683eea4f757003

if you want the ball to bounce realistically off different shapes, you'll need a way to determine the normal vector of the collision, but it wouldn't be *too* hard to add.

Go Go Gadget DBPRO!

Athlon XP 2400+ || DDR-SDRAM 1GB || Nvidia GeForce 4 Ti4200 AGP 8x 128MB

Login to post a reply

Server time is: 2024-11-26 16:40:14
Your offset time is: 2024-11-26 16:40:14