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 like billiard-balls

Author
Message
Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 31st May 2003 14:16
I did pong before, but I was kinda cheating : If the ball got to one position (ex: the wall), it had a new angle of 45° (to get it easier)
But now, I would like to know, how to do a ball really bouncing on every object it meets, with a correct angle.


This code only sends the ball to the direction where it came from

I suppose, I have to detect where the ball is touched, right ?
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 31st May 2003 14:31
just break the velocities into xvel# yvel# zzvel#
now when a z wall is hit reverse the z velocity, when y wall is hit reverse y velocity...etc

heres an example:
Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 31st May 2003 15:19 Edited at: 31st May 2003 15:20
That's the style I made for my previous pong, but it only works for a bouncing on the borders ... I would like it to work on each object I place in the field.
Example : If I put a cube on the field, the ball should bounce on it, and if I get another one, it should bounce too.

Thanks anyway
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 31st May 2003 16:23
My retro entry Sphong! has a paddle that rotates 360 degrees, and the ball bounces off it whichever angle it approaches from. The code for this is:

x#=x#+xvel#
y#=y#+yvel#
balla#=wrapvalue(atanfull(xvel#,yvel#))

(on collsion)
balla#=wrapvalue((2*a#)+180-balla#)
speed#=speed#+0.4
xvel#=speed#*sin(balla#)
yvel#=speed#*cos(balla#)

x# is the x position of the ball, y# is the y position.
xvel# and yvel# are the velocities of the ball.
balla# is the angle of motion of the ball.
a# is the angle of the paddle.

You may have to mess around with the definition of a# to get it to work properly, but it does work. It's only in 2 dimensions, however.

Once I was but the learner,
now, I am the Master.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 31st May 2003 16:45
darthster you the 3D physics top dog IMHO

I'd like to scoop out your brains and keep 'em for myself
Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 31st May 2003 17:11
Darthster, it worked fine ... and you were right, when saying, I had to mess around with a#. but I think there will be many objects to touch : I can't do a If ... then a#=47, for all of them.

I'd like to know if there is a command, which gives the number of the object, my ball is touching. (besides, my ball is object number 5)

So I could do a thing like that :
The Darthster
21
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 31st May 2003 20:48
If you're only going to be using spheres, then this should be fairly easy. To test if balls are touching, you can compare the sum of the radii to the distance between them. The distance between them by pythagoras involves a square root, so I find it helps to leave it in the squared form and square the radii. You will need to do this for every possible object collision, although you could do some hideously inaccurate but quick collision beforehand to rule out objects which are too far apart.

Also with spheres, a# is always going to be some variant on the angle between the two objects.

You only actually need to work out balla# and a# if there is a collision, which might reduce the number of calculations a bit.

Once I was but the learner,
now, I am the Master.
Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 1st Jun 2003 11:43
Well, my project, is some kind of race. (It won't be cars)
It will be in a tubular path. when colliding with the walls, it should be a sliding collision (There 's no problem with it), but there will be objects (not necessary spheres) through the path, against which our vehicle will bounce.
Lord Helmet
21
Years of Service
User Offline
Joined: 30th May 2003
Location:
Posted: 1st Jun 2003 14:49
Object collision() will return the object number that is being collided with if the secound object is 0. Ex

WallHit=object collision(1,0)

I don't know if that works for Pro but if it does you can use this number in a select case statement, or however you want. At any rate you know by number what object you hit.

I hope this helps, I'm a noob to though.

Damokles
21
Years of Service
User Offline
Joined: 28th May 2003
Location: Belgium
Posted: 1st Jun 2003 19:00
Oops, yeah ... thanks, you're right ... I totally forgot that command : I used it most to check a specific collision

Login to post a reply

Server time is: 2024-09-20 09:41:07
Your offset time is: 2024-09-20 09:41:07