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 / Ball bounce

Author
Message
Timmeh
19
Years of Service
User Offline
Joined: 15th Nov 2005
Location: Somewhere... I think...
Posted: 13th Nov 2006 02:19
I am trying to make 3d pong (without the tutorial this time around...) but I need a piece of code to make it bounce correctly. I don't want anything complicated just something that changes the direction more realisticly than adding 180 degrees to it every time it hits a wall, as that just turns it around. I would like it just to continue at the same basic angle after every bounce just in the opposite direction, i.e. if the ball hits the top wall at a 45 degree angle then it should continue in a mirrored 45 degree angle. Not sure if I described that very well, if not sorry... I don't have to have one made for me (though that would be nice ) but I need a push in the right direction. I don't know if I can write one myself though as it may require trig functions and I'm just now starting high school...

Thank you for any help given,
Tim
Timmeh
19
Years of Service
User Offline
Joined: 15th Nov 2005
Location: Somewhere... I think...
Posted: 13th Nov 2006 02:20
Almost forgot, I use DBC, gonna get DBP for Christmas I hope...
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 13th Nov 2006 02:36
If you're ok with using Sparky's free collision dll, this post might help;

http://forum.thegamecreators.com/?m=forum_view&t=89539&b=1

It has a few commented code snippets on bouncing balls around using the proper angles.

- RUC'

slicer 4 ever
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: currently: planet gamma3295
Posted: 13th Nov 2006 18:21 Edited at: 13th Nov 2006 18:22
timmeh i don't see why you woudn't want to use 180 degrees

if by what your saying you want it to go from -45 to +45 then all i see is using a wrapvalue command and adding 180 degrees to your ball.

also if you want a little randominize to the degrees you could try something like:



that well create a kinda random angle of ball effect if the ball is within the specified area.

my smiles love me =-)=-)=-)(-=(-=(-=
Timmeh
19
Years of Service
User Offline
Joined: 15th Nov 2005
Location: Somewhere... I think...
Posted: 14th Nov 2006 01:21
RUCCUS: Thank you for the link but that may still be in over my head, I'll look into that one more later... don't have much time right now.

Slicer 4 Ever: I don't want to use 180 because it would react strangely if the ball wasn't going at a perfect 45 degree angle... I.E. If the ball was going nearly straight up but not quite (a 10 degree angle for example) then adding 180 wouldn't reverse it right. Besides, adding 180 wouldn't change 45 to -45, it would change it to 125, again, not what I wanted. Thank you for trying though .
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 14th Nov 2006 01:43
Timmeh, Sparky's collision dll will only simplify things for you, not make things harder. Without the dll, you'll have to use trigonometry and some complex maths to figure out the angle the ball should bounce in based on the angle of the polygon the ball hits, and the angle the ball is moving at when it hit the polyogon. Youll also have to be sure to check if this anngle will result in making the ball go through a polygon. Sparky's dll makes this so much easier by giving you the values, making sure everything will result in a collision free bounce before continuing onto the next loop.


Id advise to take a look at the code; yes, it uses a dll and raycasting, which you may not have attempted to use yet, but the code is all commented, and if you need help you can always ask in that thread (or this one).

- RUC'

Timmeh
19
Years of Service
User Offline
Joined: 15th Nov 2005
Location: Somewhere... I think...
Posted: 14th Nov 2006 12:45 Edited at: 14th Nov 2006 12:45
Cool, thanks! I thought they might be tricky to use as every other programming tool/language I have used made them a pain to use... Thanks!

Tim
slicer 4 ever
18
Years of Service
User Offline
Joined: 11th Jul 2006
Location: currently: planet gamma3295
Posted: 14th Nov 2006 18:30 Edited at: 14th Nov 2006 18:31
actually 45+ 180 = 235 or -45 going back from 0

my smiles love me =-)=-)=-)(-=(-=(-=
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 14th Nov 2006 21:19 Edited at: 14th Nov 2006 21:20
Slicer, the point is that isnt realistic bouncing. If you threw a bal at a wall, and the ball was going 45 degrees towards the wall, you'd expect the ball to bounce in the opposite direction, not back towards you (which is what happens when you rotate by 180 degrees).

Add to the fact that using raycasting algorithms allows for polygonal objects (meaning your pool table or ping pong table or whatever doesnt have to be a square) and you'll see why sparky's dll is so useful.

Login to post a reply

Server time is: 2024-11-26 08:57:28
Your offset time is: 2024-11-26 08:57:28