Seite 1 von 1
Ball physik für fußball gesucht.
Verfasst: 18.07.2013 22:32
von True29
Hi , ich suche eine einfache ballphysik für eine fußball
also wie er sich nach dem anspielen und auslaufen verhält.
vielleicht kann mir wer dazu eine formel bereitstellen.
Bin leider kein Mathe ass
Grüße.
Re: Ball physik für fußball gesucht.
Verfasst: 18.07.2013 23:47
von STARGÅTE
Was erwartest du jetzt für eine Formel?
Deine Ballposition ändert sich mit Geschwindikeit mal verstrichene Zeit zwischen zwei Frames: x + v*dt
Deine Ballgeschwindigkeit ändert sich mit Beschleunigung mal verstichene Zeit: v + a*dt
Deine Ballbeschleunigung ist entweder das anspielen (positiv) oder das ausrollen (negativ).
Re: Ball physik für fußball gesucht.
Verfasst: 18.07.2013 23:50
von True29
danke dann hab ich doch schon mal was womit ich arbeiten kann

ich melde mich dann noch mal wenn ich nicht weiter komme.
leider klappts nicht so wie gewollt.
Vielleicht kann ja wer ein kurzes beispiel machen.
Wäre super nett

Der code unten lässt den ball übers feld fliegen ^^
kurze erklärung zum code:
ball\speed geht von 0-100
sobald der spieler den ball spielt hat er eine gewisse spielgeschwindigkeit diese veringere ich um 0.1 pro frame.
time is die aktuelle zeit
starttime die abspielzeit.
so steht das ganze momentan in meiner routine für die ballbewegung.
Code: Alles auswählen
ball\speed - 0.1
dt = time - ball\starttime
v = ball\speed * dt
x = v * dt
ball\posx + (gCos(ball\rotation) * x)
ball\posy + (gSin(ball\rotation) * x)
falls es nich ausreicht poste ich den ganzen quellcode hehe.
Re: Ball physik für fußball gesucht.
Verfasst: 19.07.2013 08:00
von Ypser
Hallo,
versuchs mal mit sowas in der Art...
Code: Alles auswählen
InitSprite()
InitMouse()
InitKeyboard()
If OpenWindow(0, 0, 0, 800, 600, "Fussball", #PB_Window_ScreenCentered) = 0: End: EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) = 0: End: EndIf
SetFrameRate(60)
Procedure.f gSin(Ang.f)
ProcedureReturn Sin(Radian(Ang))
EndProcedure
Procedure.f gCos(Ang.f)
ProcedureReturn Cos(Radian(Ang))
EndProcedure
Procedure.f dist(X1.f, Y1.f, X2.f, Y2.f)
dX.f = X1 - X2
dY.f = Y1 - Y2
ProcedureReturn Sqr((dX * dX) + (dZ * dZ))
EndProcedure
Procedure.f gATan(a.f, b.f)
ang.f = (ATan(a / b) * 57.2957795)
If b < 0
ang + 180
EndIf
ang + 90
If ang < 0 : ang + 360 : EndIf
If ang > 359 : ang - 360 : EndIf
If (ang < -359) Or (ang > 359): ang = 0: EndIf
ProcedureReturn ang
EndProcedure
Structure strBall
xpos.f
ypos.f
dir.f
speed.f
jump.f
up.f
EndStructure
ball.strBall
ball\xpos = 450
ball\ypos = 350
ball\dir = 45
ball\speed = 0
ball\jump = 0
Repeat
e = WindowEvent()
ExamineKeyboard()
ExamineMouse()
mx = MouseX()
my = MouseY()
If (KeyboardReleased(#PB_Key_Space))
d.f = dist(mx, my, ball\xpos, ball\ypos)
If (d < 30 And d > 3)
c = (ball\xpos - mx)
b = (ball\ypos - my)
a = gATan(b, c)
ball\dir = a
If (d < 5)
d = 5
EndIf
ball\speed = 60 / d
ball\up = 40 / d
EndIf
EndIf
ball\xpos + gSin(ball\dir) * ball\speed
ball\ypos - gCos(ball\dir) * ball\speed
ball\speed * 0.99
ball\jump + ball\up
ball\up - 0.1
If (ball\jump <= 0)
ball\jump = 0
ball\up * -0.5
EndIf
If (ball\xpos < 7)
ball\xpos = 8
ball\speed * 0.75
ball\dir = 180 - (ball\dir - 180)
EndIf
If (ball\xpos > 792)
ball\xpos = 791
ball\speed * 0.75
ball\dir = 180 + (180 - ball\dir)
EndIf
If (ball\ypos < 7)
ball\ypos = 8
ball\speed * 0.75
ball\dir = 270 - (ball\dir - 270)
EndIf
If (ball\ypos > 592)
ball\ypos = 591
ball\speed * 0.75
ball\dir = 270 + (270 - ball\dir)
EndIf
If (ball\dir > 360)
ball\dir - 360
EndIf
If (ball\dir < 0)
ball\dir + 360
EndIf
ClearScreen(RGB(50, 150, 30))
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
FrontColor(RGB(255, 255, 255))
Circle(400, 300, 100)
Line(400, 0, 1, 600)
Box(-1, 150, 100, 300)
Box(701, 150, 100, 300)
DrawingMode(#PB_2DDrawing_Default)
FrontColor(RGB(35, 100, 20))
Circle(ball\xpos, ball\ypos, 7)
FrontColor(RGB(255, 255, 255))
Circle(ball\xpos, ball\ypos - ball\jump, 10)
FrontColor(RGB(255, 0, 0))
Box(mx-10, my-10, 20, 20)
FrontColor(RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, "[SPACE] = Schuss")
DrawText(10, 25, "[ESC] = Ende")
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Re: Ball physik für fußball gesucht.
Verfasst: 19.07.2013 10:29
von STARGÅTE
Cool
Allerdings würde ich ehr dazu raten mit Vektoren zu rechnen und nicht mit Winkeln.
Re: Ball physik für fußball gesucht.
Verfasst: 19.07.2013 12:13
von True29
jup sieht cool aus danke für die Hilfe.
Re: Ball physik für fußball gesucht.
Verfasst: 19.07.2013 13:45
von True29
hab noch eine frage nun.
Wenn ich nun mit dem ball einen Player anschieße soll dieser praktisch abbrallen von dem.
nun is die frage wie ich die komplette 360° korrekt abfrage so das der ball realistisch abbrallt abhängig von der richtung wo er kommt.
Code: Alles auswählen
If SpriteCollision(#sprite_ball,ball\posx,ball\posy,\sprite,\posx,\posy)
If ball\rotation = 0 Or ball\rotation = 90
ball\rotation = 180
ElseIf ball\rotation = 180
ball\rotation = 90
EndIf
ball\speed = 0.1
EndIf