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.

DarkBASIC Discussion / Does anyone know how to make a ball bounce at the right angle?

Author
Message
NachoMan
22
Years of Service
User Offline
Joined: 14th Apr 2003
Location: United Kingdom
Posted: 6th May 2003 20:18
I am making breakout and I need to know how to make the ball bounce off a surface (variable) at the right angle. How exactly do you do this? I thought using the normal would help a lot. Something like ballangle# = ballangle# - normal
would this work???
ReD_eYe
22
Years of Service
User Offline
Joined: 9th Mar 2003
Location: United Kingdom
Posted: 6th May 2003 20:52
take a look at this breakout game, the capitals rem's(REM) are the ones you need to see, its some code i did a while ago so some of it is abit strange, the only problem is the ball tends to bounce in exactly the same pattern so you probably need some kinda random variable to add to the angle it bou8nces off at

ARE YOU A 3D MODELER??? IF SO WE NEED YOU!!!
EMAIL [email protected] to work on the new Star Strike project!!!
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th May 2003 21:27
If the walls are horizontal or vertical then you just need to reverse the x and y movement of the ball depending on which ball it hits...

horizontal hit = reverse y movement and keep x movement the same
vertical hit = reverse x movement and keep y movement the same

Why the hell'd you ask me for crying out loud!?!

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
NachoMan
22
Years of Service
User Offline
Joined: 14th Apr 2003
Location: United Kingdom
Posted: 6th May 2003 21:46
the problem is when i have a wobbly bat and there are different angles involved. Thnks guys!
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th May 2003 22:19
If you understand sin() and cos() then it shouldn't be too hard to work out. Something like...

x_move#=0-sin(paddle_angle#)*max_x_move#
y_move#=0-cos(paddle_angle#)*max_y_move#

or something like that. I can't think without trying it out.

Why the hell'd you ask me for crying out loud!?!

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 6th May 2003 23:17
its all simple Trig, so just get out an old gcse maths book of calculus book and look up in there...
you need to figure out first the angle of attack (where its going to hit and how many degree's it is) you all you do is mirror that angle, and your all set.
that does have something to do with CoSin however, not quite in the way that Hamish has posted.

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Hamish McHaggis
22
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 6th May 2003 23:23
lol!

Why the hell'd you ask me for crying out loud!?!

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
kevil
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: Netherlands
Posted: 6th May 2003 23:28
This works, I think.

angle#=angle of the ball movement
paddle_angle#=angle of the paddle
newangle#=wrapvalue(180.0+2.0*paddle_angle#-angle#)

Kevil

Hell IVIonkey
22
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 7th May 2003 00:25
I could be wrong, but I think it's closer to something like:

newangle# = wrapvalue( 180-(angle#-paddle_angle#) )

Login to post a reply

Server time is: 2025-05-17 02:48:46
Your offset time is: 2025-05-17 02:48:46