Kreis - Kreis Kollision

  • GM 8

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Kreis - Kreis Kollision

    Hallo,
    ich melde mich seit langem mal wieder.
    Ich habe jetzt schon eine Weile gesucht, aber noch nicht ganz was passendes gefunden. (ich habe es auch mit ball zu ball collision etc. probiert)

    Gibt es irgendwo schon eine vernüftige "Ball-zu-Ball" collision? Dabei habe ich einen kleinen Ball und einen größeren. Ziel ist es, mit der Größeren Kreis auf dem kleinen durch bounces zu balancieren. D.h. man springt auf den kleinen Ball und wird dann je nach Winkel stärker zurück befördert. Beim Winkel 90° wird jedoch wieder verkleinert mit dem Faktor *0,3, d.h. der Bounce wird wieder kleiner. Also, je schräger man den kleinen Kreis trifft, desto stärker ist die "Rückfederung".
    Ziel ist, sich immer höher "zu pendeln" in dem man auf dem kleinen Kreis "rumspringt".

    Ich suche also eine gute Kreis-Kreis Kollison. Gibt es da schon etwas?

    Vielen Dank. Gruß Paul
  • Ich dachte da eigentlich mehr an eine mathematische Lösung. Allerdings habe ich jetzt was gefunden, was mein Problem noch eher behandelt.
    Aus einem english-sprachigen Programmierer Forum stammt folgendes (Circle/LineSeg coll):

    GML-Quellcode

    1. siehe unten


    argument0.vel_x += px;
    argument0.vel_y += py;
    Das kommt von mir, und dient dazu, die Höhe des zweiten Balls zu erhöhen. Das ganze funktioniert auch wunderbar.
    Allerdings bin ich jetzt kein Mathematik-Fan und suche im Moment eine Möglichkeit, den Bounce etwas zu reduzieren also, kleiner zu machen.
    Kann da jemand den Teil in den Formeln finden, in dem man das anders Berechnen könnte? Ein einfach + bzw. - am Ende der Formel führt zu unerwünschten Effekten.

    Gruß Paul

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von Phasm ()

  • Hey nochmal,
    gibt es jemand hier, der die ganze Sach gut versteht, und mir sagen könnte, wie man den "Bounce" kleiner machen kann?
    Hier nochmal:
    Die "detect":

    GML-Quellcode

    1. // function CL_Intersect(argument0, arugment1)
    2. {
    3. x0 = argument0.tempx;
    4. y0 = argument0.tempy;
    5. x1 = argument1.x1;
    6. y1 = argument1.y1;
    7. x2 = argument1.x2;
    8. y2 = argument1.y2;
    9. n = abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1));
    10. d = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    11. dist = n/d;
    12. if(dist > argument0.radius) return false;
    13. d1 = sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
    14. if((d1-argument0.radius) > d) return false;
    15. d2 = sqrt((x0-x2)*(x0-x2)+(y0-y2)*(y0-y2));
    16. if((d2-argument0.radius) > d) return false;
    17. return true;
    18. }
    Alles anzeigen

    Und die "Reaction":

    GML-Quellcode

    1. // function CL_Reaction(argument0, argument1)
    2. {
    3. dx = 0;
    4. dy = 0;
    5. px = 0;
    6. py = 0;
    7. pen = 0;
    8. xx = argument0.tempx;
    9. yy = argument0.tempy;
    10. r = argument0.radius;
    11. x0 = argument1.x1;
    12. y0 = argument1.y1;
    13. x1 = argument1.x2;
    14. y1 = argument1.y2;
    15. lx = x1 - x0; //lx,ly is a vector parallel to the line
    16. ly = y1 - y0;
    17. len = sqrt(lx*lx + ly*ly);
    18. if(len == 0)
    19. {
    20. return 0;
    21. }
    22. rx = lx/len; //rx,ry is the unit direction vector of the lineseg
    23. ry = ly/len;
    24. nx = -ry; //nx,ny is a vector perpendicular to the line
    25. ny = rx;
    26. dx = (xx - x0); //dx,dy is the vector from x0,y0 to the circle
    27. dy = (yy - y0);
    28. dpPerp = dx*rx + dy*ry; //length of dx,dy projected onto the lineseg's direction
    29. if(dpPerp < 0)
    30. {
    31. //circle is closer to the endpoint x0,y0 than the line, project out of point x0,y0
    32. len = sqrt(dx*dx + dy*dy);
    33. pen = r - len;
    34. if(0 < pen)
    35. {
    36. //project out of the endpoint
    37. dx /= len;
    38. dy /= len;
    39. px = dx*pen;
    40. py = dy*pen;
    41. }
    42. }
    43. else
    44. {
    45. if(len < dpPerp)
    46. {
    47. //circle is closer to the endpoint x1,y1 than the line, project out of point x1,y1
    48. dx -= lx; //dx,dy is now the vector from x1,y1 to the circle
    49. dy -= ly;
    50. len = sqrt(dx*dx + dy*dy);
    51. pen = r - len;
    52. if(0 < pen)
    53. {
    54. //project out of the endpoint
    55. dx /= len;
    56. dy /= len;
    57. px = dx*pen;
    58. py = dy*pen;
    59. }
    60. }
    61. else
    62. {
    63. //circle is closer to the lineseg; project out of it
    64. dp = dx*nx + dy*ny;//dp is length of dx,dy when measured/projected onto the line's normal
    65. pen = abs(dp) - r;
    66. if(pen < 0)
    67. {
    68. //circle is inside the line; project it out along the normal
    69. if(0 < dp)
    70. {
    71. //circle is on the RHside of the line, should be projected out the +ve normal
    72. pen *= -1;
    73. }
    74. px = nx*pen;//px,py is the penetration vector which pushes the circle out of the line
    75. py = ny*pen;
    76. }
    77. }
    78. }
    79. argument0.vel_x += px;
    80. argument0.vel_y += py;
    81. }
    Alles anzeigen


    Wie gesagt, es funktioniert ja soweit, allerdings sind mir die "Rückschläge" zu stark.

    Gruß Paul