How 2D Game Collision Works (Separating Axis Theorem)

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 51

  • @areox27
    @areox27 4 місяці тому +9

    Wouldn’t it be more efficient to check if circles overlap by checking if the distance between their center points is less than the sum of their radii?

    • @Skeffles
      @Skeffles  4 місяці тому +13

      It would if you're only comparing circles but the approach I outlined in the video allows circles to be compared against any other convex shapes.

  • @FawltyPlay
    @FawltyPlay 8 місяців тому

    This is a really high quality video; I'm shocked it only has 3k views as it was the first result when searching.

  • @TonsOfHunStudios
    @TonsOfHunStudios 2 роки тому +10

    Very well explained! The graphic/animation work was excellent as well. I by know means can re-explain it as good as you did, but it's interesting to see how it's all just a matter of somewhat basic vector math layered on top of each other. Would love to see more content like this in the future :)

    • @Skeffles
      @Skeffles  2 роки тому

      Thanks Garrett! I'm glad you enjoyed the video. I will definitely look to do more similar stuff soon.

  • @AspiringHeroGames
    @AspiringHeroGames 2 роки тому +1

    It's always interesting to see how the maths works in the background to do all this stuff. Good on you for doing the calculations yourself!

    • @Skeffles
      @Skeffles  2 роки тому +1

      Yes it's super interesting. Thank you for watching!

  • @tauheedgamedev2388
    @tauheedgamedev2388 2 роки тому +1

    Great video mate, I always wondered how the magic happened in game engines and now I'm a little wiser

    • @Skeffles
      @Skeffles  2 роки тому

      Thanks Tauheed! I'm glad you learnt something.

  • @TylerGreen
    @TylerGreen 2 роки тому +3

    This is very interesting. I'd be curious to see one for 3D game collisions although I imagine it'd be a lot more complex. Looking forward to the future devlogs!

    • @Skeffles
      @Skeffles  2 роки тому +2

      Thanks Tyler!
      I'm also curious about 3D collisions. I believe you can do a similar approach with separating planes but it has more quirky situations that don't quite work.

  • @KalevaPoincare
    @KalevaPoincare 2 роки тому +2

    Great video with simple explanations for a relatively complex topic.

    • @Skeffles
      @Skeffles  2 роки тому +2

      Thanks Kaleva! I'm glad you think so.

  • @coobbyo
    @coobbyo 2 роки тому +1

    Good video! I remember collisions being confusing when I first made games in C++

    • @Skeffles
      @Skeffles  2 роки тому +1

      Thank you! They definitely are confusing and daunting when you first come across them.

  • @yordangrigorov6399
    @yordangrigorov6399 9 місяців тому +1

    Thank you! I find your pace of explaining perfect.

  • @mariovelez578
    @mariovelez578 4 місяці тому

    For polygons vs circles, you can use a voronoi diagram to check which feature of the polygon is the closest vertex or edge), and then use the axis of that feature (for edges it’s the normal, and for vertices treat the vertex as a circle with radius 0)

  • @TheShelfman
    @TheShelfman 2 роки тому +2

    This is quite complicated, but very well explained! Nice job😁

    • @Skeffles
      @Skeffles  2 роки тому +1

      Thank you Shelf! 😊

  • @ro0n655
    @ro0n655 3 місяці тому

    for circles you could just check if: distance(form circle 1 to circle 2) < circle 1 radius + circle 2 radius

  • @GamesBySaul
    @GamesBySaul 2 роки тому +1

    Hype! Glad to see your videos again! :D
    Found this really interesting and easy to follow, looking forward to more like this!

    • @Skeffles
      @Skeffles  2 роки тому +1

      Thanks Saul! I'm glad it was easy to follow along.

  • @PixelBlight
    @PixelBlight 5 місяців тому +1

    The visuals made it click for me! Such simple but elegant solution .
    Im guessing it works the same in 3D but with Vector3 normals

    • @mariovelez578
      @mariovelez578 4 місяці тому

      For 3D, you have to check the normals of each face, and the cross product between each edge of the first against each edge of the second. It’s a lot more computation, so the preferred method is the GJK algorithm

  • @RobinSeibold
    @RobinSeibold 2 роки тому +1

    Great video, both the explanation and visuals! Keep it up!

    • @Skeffles
      @Skeffles  2 роки тому +1

      Much appreciated Robin!

  • @gendalfgray7889
    @gendalfgray7889 Рік тому +1

    Usually in games there is bounding boxes, game checks bounding boxes first. If bounding boxes overlap then collision checking starts. To decrease numbers of checks normals that pointing away from collision direction (calculated from bounding boxes) could be ignored.

    • @Skeffles
      @Skeffles  Рік тому

      Yes, games often use bounding boxes to help improve their performance, especially when they have lots of complex polygons.

    • @PixelBlight
      @PixelBlight 5 місяців тому

      Not just bounding box but axis aligned bounding box (aabb) making it even faster!

  • @GingerNingerish
    @GingerNingerish 2 роки тому +1

    Very informative good job. Increadible editing too, very well presented!

    • @Skeffles
      @Skeffles  2 роки тому

      Thank you Ginger. I'm glad you liked it!

  • @Jalecko
    @Jalecko 2 роки тому +5

    one day, one day i shall make a game with diagonal map colisions

  • @jmgames6628
    @jmgames6628 2 роки тому +1

    Interesting video! The sound quality didn't seem the best though, seemed like there was a bit of an echo. I don't remember noticing any issues with the sound in your videos before, but you haven't made one in while of course! Good to see you getting back into it, anyway!

    • @Skeffles
      @Skeffles  2 роки тому +1

      Thanks! I'll have to see if I can improve the audio quality.

    • @jmgames6628
      @jmgames6628 2 роки тому +1

      @@Skeffles That'd be good, good luck with it!

  • @valentineDev
    @valentineDev 2 роки тому +1

    interesting video! you explain it really well!

    • @Skeffles
      @Skeffles  2 роки тому

      Glad you think so. Thanks Valentine!

  • @ZJShepherd
    @ZJShepherd 8 місяців тому

    Fantastic, thank you!

  • @microdavid7098
    @microdavid7098 2 роки тому

    nice. Great explanations

    • @Skeffles
      @Skeffles  2 роки тому +1

      Thank you David!

  • @FlorianMaeder
    @FlorianMaeder 20 днів тому

    3:35 I must be missing something. How do you get to that separation axis in code where you cannot look at the shapes and just draw a line and then take the dot product of that?
    All the talk after that on projecting onto that separation axis doesn't compute for me, because I don't know how to get to that axis.

  • @BrickGriff
    @BrickGriff 7 днів тому

    I want to try both this and signed distance functions. Won't these slow down my game if every entity is checking each other one? Maybe I have to use an oct-tree too?

  • @Genpaku
    @Genpaku 2 роки тому

    Hey Skeffles long time no see, cool video, I've done something like this to test collisions but never know how it's called.

    • @Skeffles
      @Skeffles  2 роки тому +1

      Hey Genpaku, thank you!
      It's definitely not an easy to find thing when you first start out. I'm hoping this video helps with that.

  • @josiahjack455
    @josiahjack455 3 місяці тому

    5:43 wait, they're just circles. Isn't it just checking if the distance between the two is less than the sum of their radii? No projection needed.

    • @Skeffles
      @Skeffles  3 місяці тому +1

      That is the case if you're only using circles. The method I outlined in the video allows for checking circles against any convex shape.

  • @gsestream
    @gsestream 7 місяців тому

    how about just intersections and overlap

  • @SomeAndrian
    @SomeAndrian 3 місяці тому

    A better approach is the GJK algorithm
    ua-cam.com/video/ajv46BSqcK4/v-deo.html