I have 4 balls. When I get to the point of crashing, I got the speed,
but how about the angle? I want it to be done with the crash-in-to ball...
every ball has these two properties: Speed and Angle
I need help!
Thank you,
Arie.
Printable View
I have 4 balls. When I get to the point of crashing, I got the speed,
but how about the angle? I want it to be done with the crash-in-to ball...
every ball has these two properties: Speed and Angle
I need help!
Thank you,
Arie.
Look at attached and see what you come up with
Nice circles, but, I need a code for the crashing angle set.
VB Code:
Sub PlayerBlockPlayer(iPlayer As tPlayer, iWithPlayer As tPlayer) With iPlayer If Distance(iPlayer, iWithPlayer) <= 32 Then .plVelocity = Int((iWithPlayer.plVelocity + .plVelocity) / 2) iWithPlayer.plVelocity = Int((iWithPlayer.plVelocity + .plVelocity) / 2) iWithPlayer.plAngle = Int( _ (iWithPlayer.plAngle + _ GetAngle(CSng(iWithPlayer.plPosition.posX), _ CSng(iWithPlayer.plPosition.posY), _ CSng(.plPosition.posX), _ CSng(.plPosition.posY)) _ ) / 2) .plAngle = Int( _ (.plAngle + _ GetAngle(CSng(iWithPlayer.plPosition.posX), _ CSng(iWithPlayer.plPosition.posY), _ CSng(.plPosition.posX), _ CSng(.plPosition.posY)) _ ) / 2) End If End With End Sub
GetAngle gets the angle of the line between the two balls.
I need help here.
Arie.
I know this code is wrong somewhere...
Please help.
Two ways of helping:
1) Tell where the wrong step is made.
2) Give a code for ball collision, angle directing.
Thank you anyhow,
Arie.
New_dx_and_dy_ForTwoBallCenters needs these 'current' values
for both circles: posx, posy, dx, dy
if you don't have them, add dx and dy as members of your type.
'declares
Dim slope As Single
Dim perpSL As Single
Dim rise As Single
Dim run As Single
Private Sub New_dx_and_dy_ForTwoBallCenters(BallCenter_A As YourType, BallCenter_B As YourType)
Dim riseA As Single
Dim runA As Single
Dim riseB As Single
Dim runB As Single
Dim x_solvB As Single
Dim y_solvB As Single
Dim x_solvA As Single
Dim y_solvA As Single
Dim mRatioA As Single
Dim mRatioB As Single
Dim mSum As Single
Dim mB As Single
Dim mA As Single
Dim dxA As Single
Dim dyA As Single
Dim dxB As Single
Dim dyB As Single
Dim vxAverage As Single
Dim vyAverage As Single
Dim axPast As Single
Dim ayPast As Single
Dim bxPast As Single
Dim byPast As Single
Dim axFuture As Single
Dim ayFuture As Single
Dim bxFuture As Single
Dim byFuture As Single
axPast = BallCenter_A.posX - BallCenter_A.dx
ayPast = BallCenter_A.posY - BallCenter_A.dy
bxPast = BallCenter_B.posX - BallCenter_B.dx
byPast = BallCenter_B.posY - BallCenter_B.dy
dxA = BallCenter_A.posX - axPast
dyA = BallCenter_A.posY - ayPast
dxB = BallCenter_B.posX - bxPast
dyB = BallCenter_B.posY - byPast
mA = 1
mB = 1
rise = (BallCenter_A.posY - BallCenter_B.posY)
run = (BallCenter_A.posX - BallCenter_B.posX)
Call SlopeAndPerpendicular
mSum = mB + mA
mRatioA = mA / mSum
mRatioB = 1! - mRatioA
vxAverage = BallCenter_A.dx + mRatioB * (BallCenter_B.dx - BallCenter_A.dx)
vyAverage = BallCenter_A.dy + mRatioB * (BallCenter_B.dy - BallCenter_A.dy)
axPast = axPast + vxAverage
ayPast = ayPast + vyAverage
bxPast = bxPast + vxAverage
byPast = byPast + vyAverage
mB = slope - perpSL
y_solvA = (axPast - BallCenter_A.posX + slope * ayPast - perpSL * BallCenter_A.posY) / mB
x_solvA = BallCenter_A.posX + perpSL * (BallCenter_A.posY - y_solvA)
y_solvB = (bxPast - BallCenter_B.posX + slope * byPast - perpSL * BallCenter_B.posY) / mB
x_solvB = BallCenter_B.posX + perpSL * (BallCenter_B.posY - y_solvB)
axPast = 2 * x_solvA - axPast + vxAverage
ayPast = 2 * y_solvA - ayPast + vyAverage
bxPast = 2 * x_solvB - bxPast + vxAverage
byPast = 2 * y_solvB - byPast + vyAverage
BallCenter_A.dy = ayPast - BallCenter_A.posY
BallCenter_A.dx = axPast - BallCenter_A.posX
BallCenter_B.dy = byPast - BallCenter_B.posY
BallCenter_B.dx = bxPast - BallCenter_B.posX
End Sub
Private Sub SlopeAndPerpendicular()
If run <> 0 Then
slope = rise / run
Else
If rise > 0 Then
slope = 999999
perpSL = 1 / slope
ElseIf rise < 0 Then
slope = -999999
perpSL = 1 / slope
Else
slope = 0
End If
End If
If slope <> 0 Then
perpSL = -1 / slope
Else
If run > 0 Then
perpSL = -999999
slope = 1 / perpSL
ElseIf run < 0 Then
perpSL = 999999
slope = 1 / perpSL
Else
perpSL = 0
End If
End If
End Sub
What is all this code for? How do I test it?
I need a simple code:
Angle = ...
After hitting the other ball..
Some calculation..
Arie.
You need to reverse the angle
.Angle = -.Angle
1. Copy the 4 new Dims.
2. Paste into the module or form that has your collision code.
3. Copy the 2 new subs
4. Paste into the modulr or form that has your collision code
5. If need be, change the 4 Dims and Private Sub New_dx_.. to public
6. When you find a collision, call New_dx_and_dy_ForTwoBallCenters.
7. Make sure you are using dx and dy as members of your type
I updated mod_VSA_Surface. AlphaBlit and RGBBlit have a new parameter, and I fixed a bug in FillSurface.
You see, dafhi, no offence but.. I prefer no to use your graphic engine.
I just need to know to what angle to set a ball who hit another ball?
I have the angle of the hitting ball and the angle of the hit ball.
What should I do?
Arie.
Reverse The Angle
Angle = -angle
:D :D :D :D
Tried that...
No way! I'm talking about two balls who hit one each other.
I need to set the correct angle to both balls counting the current angle of each.
How???
Arie.
try this code....its not perfect but it works
VB Code:
For j = 0 To BallStack.Count 'check collition If Distance(.X, .Y, BallStack.Ball(j).X, BallStack.Ball(j).Y) <= BallStack.Radius * 2 And i <> j Then .Speed = (BallStack.Ball(j).Speed + .Speed) / 2 '.Angle = (GetAngle(BallStack.Ball(j).X, BallStack.Ball(j).Y, .X, .Y) + .Angle) / 2 .Angle = GetAngle(BallStack.Ball(j).X, BallStack.Ball(j).Y, .X, .Y) End If Next
This is the part that i'm interested in.
Does anyone has a better code from this one that does the same but in a better way?
Thank you,
Arie.
You should be able to figure it out from this example.
Works great!
but let me know where are you setting the new angle of the balls
after the hit?
Arie.
Hi..
Myself and Cyborg .. some time back had tried hard for making a snooker game..
I found at some place in the net that the perfect collision cannot be simply calculated ..
i.e... simply check whether it has hit a ball or not at every frame..
We must calculate the collision and angle prior to actual collision..
There was some algorithm.. I guess if you search it in the net for Perfectly Elastic Collision, u will find some help..
Regards,
Pradeep
Cyborg.. did u see that bounce.zip.. cool ..
got to read the code now..
Well dafhi cud you explain the algorithm..
Thanks,
Pradeep
Yes i saw it. Its really nice! Im gonna go read that code...Quote:
Originally posted by pradeepkrao
Cyborg.. did u see that bounce.zip.. cool ..
HI,
Theres a problem..
Since it is two balls it works fine..
as you make a ball array.. the performance drops drastically.
More over to check the collision.. you need to check for
n x n - n times... it becomes slow and the velocity increases...
I guess we too had the same problem.....
maby you could simplify the algorithm a bit...i havent looked at it yet so im not sure what can be done.
Well?
Still, I don't really understand that code. anyhow, I believe that there's a simpler code for that.
Anyone with code?
Arie.
Arie have you tried bugging gamedev.net forums? They're specifically games and you might have a better chance hitting the entire forum up for code... just a suggestion
NOMAD
Thanks.
I'll check it out.
Arie.
I checked out the site..
I did not find anything useful for me...
It's all c++ there...
Can someone find the simple way of setting the angle for two
balls who hit one each other?
Arie.
did you look at the pool game that i attached? its a pretty simple way of determin the new angle...
Works almost perfect. I need the final touch.
Some help?
Arie.
Take a look at this: http://rookscape.com/vbgaming/tutBT.php Its got Lucky's Hybrid Engine which uses directDraw and Direct3D so you can make a direct draw game but use some of the features from Direct3D e.g. Rotating, Alpha blending, Alpha One blending, and some other stuff.
I read most of the other posts and I didn't see one that solved your rotaing/speed problem, and using Direct3D to rotate images is as fast as not roatating them.
I based my DirectDraw engine on the ideas from Lucky's site and it works really fast, couple of bugs here and there tho. Like pixel perfect collision detection between rotated sprites, I managed to put a simple error somewhere and still can't find it.
Anyway tho I advise you at least take a look cos the code was really useful for me.
What was that for?
Does it have something to do with my question?
I'm talking about Ball hitting... angle setting...
Arie.
Didn't you need some code for rotating sprites? I was reading the posts at the start and they were on about rotaing images but I couldn't see a solution that you said was fast enough.
Oh... I asked it long ago.. I'm sorry..
I'll check it out.. Thanks anyway.
Arie.
I found it very hard to understand...
Does anyone have a simple ball hitting code?
Arie.
When are you going to understand that graphics programming is not simple....it is not to hard to understand, but you should start with something simple, and then go the levels.....
I see that this thread is getting very annoying... :(
So, I decided not to reply any more on this thread.
If i'll have more specific questions... I'll ask away..
So, in the meanwhile, I don't have such questions..
A VERY BIG THANK YOU FOR ALL WHO TRIED TO HELP...
Arie.
P.S.
Do not post anymore replys..
QUOTE=johan3]he guys my name is johan i am from holland i need your help, i have to make a game pimpampet in microsft visual basic but i just can't make it it's to damn difficult i wonder if you could help me it is very important i have to delivered monday please, thank you[/QUOTE]