I'm looking for a way for a ball to bounce off a line.
ok i have a ball going on a 90' angle to a
line (152,200)-(192,160) which has a slop of -1
Printable View
I'm looking for a way for a ball to bounce off a line.
ok i have a ball going on a 90' angle to a
line (152,200)-(192,160) which has a slop of -1
any gravity? Any friction? Any collision detection? Is it only the graphical part your interested in? What are you trying to accomplish?
NO gravity NO friction
start position of the ball? does it have a radius?
velocity? in pixels please
image/picturebox? shapecontrol ddraw, how do you draw the ball?
B_angle(1)=90
B_Velocity(1)=1
angleofball = B_angle(ball) * (2 * 3.14159265358979) / 360
X = Pball(ball).Left + Cos(angleofball) * B_Velocity(ball)
Y = Pball(ball).Top + Sin(angleofball) * B_Velocity(ball)
This works
i have the ball at 50,10
I'm making pong
the line with the slop is the thing to hit the ball back
[Edited by BIacksun on 10-14-2000 at 05:59 PM]
The ball doesn't hit the wall, do you want me to change the values so that you have it bounce with slopes?
BTW, don't calculate ball position by trigonometry, calculate vectors by angle instead.
I sent you an example of a Ping Pong game, check your mail. It's not the most advanced, but it works :rolleyes:.
Hope that helps.
i want somthig like this
If Y > (?line.Y2?) Then
m = (.Y2 - .Y1) / (.X2 - .X1)
B_angle(ball) = ???????????????????
End If
so when the ball hits the line, the ball will change it's
angle.
[Edited by BIacksun on 10-14-2000 at 06:23 PM]
The math behind it was a bit hard to figure out and i'm still not sure if it will work, anyway here's the collision point and the exit angle:
x1,y1,x2y2, the wall coordinatesCode:kw = (y2 - y1) / (x2 - y1)
kb = Tan(angle)
bw = y1 - k * x1
bb = ballY - k * ballX
'collision point
cx = (kw * x1 + bw - bb) / kb
cy = kw * cx + bw
'exit angle
angle = Tan(kw) + 180 - Atn(Abs((kw - kb) / (1 + kw * kb)))
angle, the angle of the ball velocity
BTW, i have an old vb3 sample that demonstrate this better, but it's a real mess to understand it, anyway it works
what is "k"
and what do i do with
IS this for the ball to make it to the line?
bw = y1 - k * x1
bb = ballY - k * ballX
'collision point
cx = (kw * x1 + bw - bb) / kb
cy = kw * cx + bw
I need a example of this stuff
[Edited by BIacksun on 10-14-2000 at 08:53 PM]
k is the k in line equation: y=kx+b
ah sorry should be kb for the ball and kw for the wall
bw = y1 - kw * x1
bb = ballY - kb * ballX
is it not
y=mx+b
m = rise/run (slop)
whatever, were talking about the same thing
thanx for the help
but i faild.