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 / Angle Mangle

Author
Message
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 14th Jan 2004 19:31
Hi. Im new here, this is my 1st post. im making a game called bricks/arkanoid. so far everythings working fine except 1. When the ball bounces off the player object (a rect. box), the ball needs to change direction as well as the angle it moves in. the angle change is based on where the ball hits the rect box. This is what i've tried so far.



It works ok,but i want something more realitic. i tried using the distance formula but it just got worst. If the ball is moving left,and hits the left side of the rect box,then its angle must decrease and vice versa. When i rotated the object before the main loop,rotating on the z axis gives the angle the ball moves in.

There are sometimes 3 balls in motion at once, hence the for next loop. AB(a) = 1 means ball a is active. Please help me. Thanks.

If it wasn't for the last minute, nothing would get done!
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 14th Jan 2004 23:30
help someone plz. click the source button to see the source.
^
|
|

If it wasn't for the last minute, nothing would get done!
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 15th Jan 2004 19:29
will no one reply to me? well isn't that sad

If it wasn't for the last minute, nothing would get done!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2004 05:26
In the original games, the ball never hit the side of the paddle. So basically, all you have to do is check to see if the ball's X coordinate is between the ends of the paddle, and if the ball's Y position is lower the top of the paddle.


_
|_|
x1-------x2

B = ball
R = ball radius
P = paddle(player)
L = 1/2 paddle length
Assuming that "px" is the center of the paddle and bx and by are the center of the ball:

if (bx > px-L and bx < px+L and by+R > py) then ball hit paddle

This is the code I used to reflect the ball from the paddle


Because the ball reflects off at sharper angles when it hits closer to the edge of the paddle, the reflection angle is different.

"eureka" - Archimedes
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Jan 2004 05:26
Oh ok, this forum deletes white spaces, so no neat picture!

"eureka" - Archimedes
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 16th Jan 2004 22:22
hey thanks! i wil try that code now. but my paddle is in 3d so it will hit the sides. i'll just add that the ball y position > paddle y position - size y(paddle). thanks again. hope it works.

If it wasn't for the last minute, nothing would get done!
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 16th Jan 2004 23:15
is this how it supposed to look? it doesnt work. the ball acts as though its colliding all the time. how do i make that code snippet button?


If it wasn't for the last minute, nothing would get done!
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 16th Jan 2004 23:16
oops,how do i put code in that button?

If it wasn't for the last minute, nothing would get done!
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 17th Jan 2004 09:42
inbetween [c0de]] and [/c0de] so if i made that right it would look like this:
, get it?

VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 17th Jan 2004 11:46
oh thanks.
.
i have 3 spheres that i want to check for collision against the player box object. using object collision(a,4)>0 where a is one of the 3 spheres and 4 is player box object decreases fps too much. i tried the math collision, like this

This doesnt work because the spheres behave as though they are always colliding with object 4. Is there something wrong with the math? Also,if i want to detect collision between the 3 spheres and 72 box objects, how do i do it?

If it wasn't for the last minute, nothing would get done!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jan 2004 19:21
The problem is, you have 3 balls, but only 1 angle value. 3 balls need 3 different angle variables. So you need to create an array.

dim Ang#(3)

if ox# > opx# then Ang#(a) = dist#*1.4*S_F
and so on...

Since ox#, oy#, and the other variables are defined each loop, and aren't used outside the loop, you won't need an array for those.

"eureka" - Archimedes
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 17th Jan 2004 20:40
i see what you saying but if i use the Object Collision command,it works for all three balls,even with only one angle variable because the objects angle is updated in the loop. the math collision doesnt work. the ball jerks up and down while moving upwards. This is my entire program...click the source button. thanks a lot for your help Phaelax

If it wasn't for the last minute, nothing would get done!
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 17th Jan 2004 20:43 Edited at: 17th Jan 2004 21:00
oh sorry, this is the info in the txt file that you'll need.

Ok nevermind! i tried something and now the angle the paddle reflects with is working. thanks. now just one last problem, the collision of the 3 balls with 72 or more bricks. i cant get the math collision correct.

If it wasn't for the last minute, nothing would get done!
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Jan 2004 02:05
I can't get your code to compile.

If AB(3) holds the object number of the 3 balls, and brick(72) holds the object number of the bricks, then...

for i=1 to 3
for k=1 to 72
if hit(ball(i), brick(k))=1 then reflect ball
next k
next i

"eureka" - Archimedes
VishalC
21
Years of Service
User Offline
Joined: 14th Jan 2004
Location:
Posted: 18th Jan 2004 12:22
what's wrong with my code? it compiles fine on my pc. guess its all the missing files, oh well.

i tried doing that but it just doesnt work. i think its ok now because after using your paddle reflection code,the whole program runs smoother and faster,even with DB collision commands. now im sitting at 60 fps. Im going to start with the menu now and make all the levels. Do you have any suggestions for making a cool menu? i was thinking of using images and using the sin wave to distort the currently selected one. sound good? Thanks a lot for the help.

If it wasn't for the last minute, nothing would get done!

Login to post a reply

Server time is: 2025-05-22 16:36:13
Your offset time is: 2025-05-22 16:36:13