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 / Ye olde bouncing ball question...

Author
Message
Daz
21
Years of Service
User Offline
Joined: 26th Dec 2002
Location: United Kingdom
Posted: 15th Feb 2003 20:15
Hello, I want to create the effect of a bouncing ball that bounces of walls. I'm thinking of doing this by re-pointing the ball so it moves in the "reflected" direction.

Say the ball bounced on a wall 45 degrees in X pos, 45 degrees in Y pos and 45 degrees in Z pos. How would I point the ball to go all 45 degrees the other way?

Hope that made sense...
DarkBASIC Professional is the best programming utility.
8/10 Housewives agree!
Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 15th Feb 2003 21:23
45 degrees in which other way?
If something is going x degrees in one direction and you want to go opposite direction wrapvalue(x-180).

If you want it to go in complete opposite direction(for X,Y and Z) then

(where ball is object 1) This only works if ball has to bounce in complete opposite direction.

Those of you who think you know everything are annoying to those of us who do.
Daz
21
Years of Service
User Offline
Joined: 26th Dec 2002
Location: United Kingdom
Posted: 15th Feb 2003 21:28
Thats almost what I want, I might tinker around with that. Thanks.

DarkBASIC Professional is the best programming utility.
8/10 Housewives agree!
Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 15th Feb 2003 21:48
I did a pinball game in visual basic. I spent about 6 months getting the whole code for a realistic bouncing effect(all worked out in maths class). Then I no longer had access to visual basic before I got it finished so I have to redo the whole thing for dark basic (this should be easier this time though)

Those of you who think you know everything are annoying to those of us who do.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 16th Feb 2003 00:37
reverse velocities easiest way:

Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 16th Feb 2003 01:17
Reverse velocities doesn't work for all situations.

Those of you who think you know everything are annoying to those of us who do.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 16th Feb 2003 11:06
best way to achieve effect daz wanted - imho
Daz
21
Years of Service
User Offline
Joined: 26th Dec 2002
Location: United Kingdom
Posted: 16th Feb 2003 14:28
Uhhhh.....thanks? I'm not going to get my entry done in time, am I?

DarkBASIC Professional is the best programming utility.
8/10 Housewives agree!
Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 16th Feb 2003 18:44
Reverse velocities is bad programming practice. In a language that gives every object a direction you shouldn't have objects travelling backwards.

Those of you who think you know everything are annoying to those of us who do.
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 16th Feb 2003 21:11
Surely setting your own velocities and ignoring the in-built rotations gives you greater control, in that you can move the objects without having them pointing the right way, useful for spaceship thrust and stuff.

To get any useful object manipulation you should really always break up the velocities and forces into x y and z components. This makes it much easier to manipulate the object's movement in any one dimension.

To bounce stuff, you want to reverse the velocity in the direction from the object to the wall. Find the angle from the centre of the ball to the wall it is bouncing from, and use that angle and some trigonometry to reverse the direction of movement along that angle. Simple, really.

Once I was but the learner,
now, I am the Master.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 16th Feb 2003 21:26
i with u darthstar
reversere velocity is what happens in real life
if you throw a ball at a wall, it doesn't turn back to face u it just bounces back toward you (ie it's velocity is reversed).
it not bad programming practice to make your code follow real life physics - again imho
Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 16th Feb 2003 23:52
DB allows you to split direction up into X,Y and Z components. In Physics, you don't say something is travelling NW at -57m/s, you say it is travelling SE at 57m/s. With spaceship thrust it makes sense to only change velocities, but a ball looks the same from all directions(unless it's textured, in which case it's easy to scroll it around in the opposite direction from the way you rotate the ball). Velocity is split into two things: speed and direction. Speed is never negative, so to reverse a velocity you don't negate the speed, you reverse the direction, so technically the ball does change direction and go at the same speed.

and what does imho mean?

Those of you who think you know everything are annoying to those of us who do.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 17th Feb 2003 01:26
imho=in my humble opinion

we'll have to agree to disagree on this one - if a ball is going forward then hits a wall and comes back at you its going in opposite direction so it's speed is reversed - we shouldn't make simple physics more complecated than they need to be - imho
Witch Bomber
21
Years of Service
User Offline
Joined: 25th Jan 2003
Location: Scotland
Posted: 17th Feb 2003 01:57
Unless the ball is going perpendicular to the wall in both dimensions the wall is built on, it will not bounce in the exact opposite direction so it's speed is not reversed.

The reason VB was harder than DB was because I had to use speed to do things as opposed to just using directions. It was extremely complicated to get a general formula to change speeds correctly in all situations

Those of you who think you know everything are annoying to those of us who do.
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 17th Feb 2003 02:13
using x,y,z speed insted of direction allows you to do a lot more.
The rotate and move commands are great when they will work but it would be a pain to be working on a game and half way through have an idea that reqired more control of movement and have to re-write code.

Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 17th Feb 2003 11:55
"Unless the ball is going perpendicular to the wall in both dimensions the wall is built on, it will not bounce in the exact opposite direction so it's speed is not reversed."

if the ball hits a wall on it's x axis then it's x velocity is reversed(less a certain amount because of the loss of kinetic energy in the collision- but pong games don't loose speed in collisions etc). If it hits a wall on its y axis the y velocity is reversed.

now if a ball hits a bat on its x axis and the bat is traveling along the y axis at speed then the ball does spin but the ball does not follow the direction it's facing. But not only is it's x velocity reversed but its y velocity is affected(the amount depends on the speed of the bat).
Daz
21
Years of Service
User Offline
Joined: 26th Dec 2002
Location: United Kingdom
Posted: 17th Feb 2003 16:28
O_o......o_O..................?????????????????

1) I am not good at maths

2) I am new to programming.

Basically, summing up in one expression, huh?

DarkBASIC Professional is the best programming utility.
8/10 Housewives agree!
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 17th Feb 2003 18:20
it aint hard daz

have 3 variables:
xvelocity#
yvelocity#
zvelocity#

each loop do:

then check to see if ball hit any walls, if it has reverse the relevant velocity.
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 18th Feb 2003 01:14
It is harder if the walls aren't perpendicular to the axes though. However I can't quite remember the maths for that, except that it involves the angle from the centre of the ball to the wall.

Once I was but the learner,
now, I am the Master.
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 18th Feb 2003 03:36
a 3d pong that takes into account gravity, the correct transfer of kinetic energy, etc - AND set inside a sphere would be good practise. I bet darthstar could do one in the time it takes to boil a kettle - 'cus he good at 3d physics
CarlTaylor
21
Years of Service
User Offline
Joined: 13th Jan 2003
Location: United States
Posted: 18th Feb 2003 07:46
Darthstar, which axis/axes were you talking about?

my explanation: The ball is headed toward a wall traveling at -1z/second (down 1 unit every second), 1x/second (forwards 1 unit every second) and 0y/second (not turning left or right).

From the side it would look like this. (the ball is a circle, the dashed line is the ground. Shown are six of the ball's stages)

O
O
O
O
O
O

------------
Now we put a wall in front of it. The wall is perpendicular to the ground. The slope of the ground is 1x for every 0y (0/1). The slope for the wall is 0x for every 1y(1/0). Lets look at how it will be now.

O |
O |
O |
O |
O |
O|
|
------------

Now as the ball hits the wall, in this case it will not change "Y" directions because it is hitting the wall at a 90 degree angle to the direction the wall runs. To find out which direction it will bounce if this is not the case, it is very easy. Measure angle made by the direction of the ball and the wall. Your new direction can be found by measuring then angle of entrance on the opposite side of the wall.

| /
|35°/
| /
| /
|O
| \
| \
|35°\
| \

Apply this same thing to your X, Y, and Z. Remember: (angle of departure) = (angle of entry), and (slope of departure) = -(slope of entry).

hope you dont get too confused, and i hope my diagrams come out alright.

-KLK

(PS just makin sure you know all that stuff was without gravity or air resistance or elasticity and all that stuff)

baseball = life
CarlTaylor
21
Years of Service
User Offline
Joined: 13th Jan 2003
Location: United States
Posted: 18th Feb 2003 07:47
damn, the diagrams didnt come out. evidently this doesnt allow more than one space in a row... disregard them.

baseball = life
CarlTaylor
21
Years of Service
User Offline
Joined: 13th Jan 2003
Location: United States
Posted: 18th Feb 2003 08:08
i put the pics on my site go to: www.geocities.com/chronocide2005/bounce

baseball = life
Daz
21
Years of Service
User Offline
Joined: 26th Dec 2002
Location: United Kingdom
Posted: 18th Feb 2003 13:05
It's okay now, guys. I'm not going to learn programming any time soon so chill, take a break, help the other n00bs that would get this stuff better than I can.

DarkBASIC Professional is the best programming utility.
8/10 Housewives agree!

Login to post a reply

Server time is: 2024-11-24 01:40:05
Your offset time is: 2024-11-24 01:40:05