GM:S 1.4 Collision between balls with physical effect

Discussion in 'Programming' started by Bhreno, Oct 6, 2019.

  1. Bhreno

    Bhreno Member

    Oct 5, 2019
    In my current project, there are balls that randomly come out of the map (without gravity) and on the way they can collide with 3 different things:
    > solid blocks where they hit and deflect.
    > breakable blocks, where they destroy and deflect.
    > other balls, they hit and deflect each other.

    I would like to make sure that when the balls collide, the one with the highest speed would end up acting at the speed and direction of the other.
    Example: Two boys play ball and each is kicking one. They kick both in the same direction. One is with speed force 10, the other with force 20. The higher force will logically "push" and change the direction of the other when both collide. But I can't do it in GMS. The Bounce functions I try to use always end up just "reversing the course" after the crash, rather than the actual physics effect.
    can you help me?
  2. Relic

    Relic Member

    Jun 27, 2017
    Is this a physics room? I’m guessing not.

    Are the balls restricted to one dimensional movement? You have made it sound like it is.

    For elastic collisions (no loss of energy) two objects of identical mass swap velocities along the dimension of the collision.

    Your collision code will have to:
    1) get the speed and direction of both balls.
    2) swap the speed and direction
  3. 2Dcube

    2Dcube Member

    Jun 23, 2016
    Have you considered using game maker's built in physics system? The balls would behave very naturally.

    Alternatively, you can do the calculations yourself when 2 balls collide. You'd need the x and y velocity of each and the angle of impact between them.

    Here is a tutorial that explains ball collision math:
    It's for Flash Action Script but should be similar to GML.
  4. Bhreno

    Bhreno Member

    Oct 5, 2019
    Look, each ball has its speed and direction set and can even make a collision with physics. However, when they collide, sometimes they just cross another. Already tried to change the mask, precise, rectangular, full image... Nothing of them worked. The collision still causes one ball to lock on the other several times.
    What can I do to prevent this from happening? Like a check steps or something...[​IMG] [​IMG]
    Last edited: Oct 7, 2019

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice