Collision Detection (An Overview) (UPDATED!)

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

КОМЕНТАРІ • 45

  • @MacroPixel
    @MacroPixel  3 роки тому +26

    This was meant to be published before the RNG one, but apparently UA-cam orders videos by when they were first made public rather than when they were first uploaded. Sorry for the duplicate notifications!

  • @landru27
    @landru27 Рік тому +40

    1:43 and 3:39 : Correction : AABB is frequently used for non-rectangles, and for rotated rectangles. The idea is to wrap each polygon -- regardless of what it is or how it is rotated -- with a rectangle suitable for this kind of check. It's an optimization over the naive approach of using each polygon's natural/real boundaries, because it's very fast to determine this wrapping -- this "axis-aligned bounding box". Additionally, as such, it can an is used as a "middle" phase -- it's not necessarily something one uses instead of SAT, but can be used alongside SAT as a quick check after the broad phase and before SAT, since SAT is so heavy. Some sources even classify AABB as a broad phase technique. I hope this info helps you and your viewers.

    • @MacroPixel
      @MacroPixel  Рік тому +7

      Sorry it took me so long to respond!
      I guess when I said AABB only worked on non-rotated rectangles, I meant that the hitboxes _themselves_ had to match these criteria, but it can still be used on non-rectangles or rotated objects. I added this to the description as a clarification, since I probably should've done a better job of communicating it. Regardless, the bit about AABB being narrow phase was incorrect, so I added that to the description as a correction. If anything else is wrong, feel free to let me know. Thanks for your help :)

    • @vadim_shashin
      @vadim_shashin 2 місяці тому

      That’s useful!
      Thinking about writing my own simple physics engine instead of using box2d and was wondering about the best approach on detecting collisions
      3 phases like this would work perfect 🙂

  • @taizeen1805
    @taizeen1805 5 місяців тому +3

    You're animations and explanations are really well done, thanks for making this video.

  • @chaingunguy4722
    @chaingunguy4722 11 місяців тому +4

    This video is so high quality and informative. It's a shame it has so few likes and views.

  • @walnut7137
    @walnut7137 11 місяців тому +1

    This is an incredible video, everything from the animation to the explanation! You deserve so much more attention. 🎉

  • @atharvaupadhye9819
    @atharvaupadhye9819 7 місяців тому +1

    your humble disclaimer made me subscribe you even before starting the video

  • @richardericlope3341
    @richardericlope3341 6 місяців тому +1

    Re: SAT
    I don't get the "parallel" and "angle" part.
    The last time I implemented SAT, I had to get the edge normal(the axis), project each vertex to the normal to get the min and max edges then test that with the other polygon whether both min-max overlap.
    If there is a separating axis, get out of the test early since only one separating axis is needed to determin if they are not colliding.

  • @myelingd194
    @myelingd194 3 роки тому +1

    Ive seen one of your videos from a long time ago, amd you have improved alot

  • @aggold6757
    @aggold6757 3 роки тому +1

    i feel cool rn, i called it in the previous video comments

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

    Great and informative video! I loved it

  • @zyfryth
    @zyfryth 2 місяці тому

    This is very interesting, but there is a question of how to predict the collision, since in a lot of cases finding out that the objects overlap is too late, because you might never want them to intersect at any point in time. Does that mean you have to run the check at every frame??? It is one thing to calculate detection in a static frame and I guess a whole different beast, to calculate this dynamically with thousands of objects moving on the screen.... :D

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

    THANK YOU DUDE

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

    "however, i'm an idiot" i let out a chuckle, maybe two :)

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

    4:07 when Marco Pixle goes 3D

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

    how do i know what is the point where i have to apply the impulse though?

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

    maybe it isn't what you aim to do, but I absolutely LOVE videos like this but that get into every detail in it's implemetantion, 3blue1brown does that but in math and some other channels do that but in computer sience, I hoped this video would provide me that but sadly is just an overview
    I wanted to say this so you know that there is, at least, someone that would want that

  • @m4rt_
    @m4rt_ Місяць тому

    What about GJK and EPA?

  • @all69stoff
    @all69stoff 2 місяці тому

    Bro’s becoming RGME

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

    does anyone know how to implement section 4 I’ve been trying to find out how but I can’t find any sources, and when I tried implementing it myself it worked but had problems, please 😭😭💀

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

      For SAT you want to determine all the vertices of the polygons that you want to collide (assuming you’re doing polygon v polygon collisions). You then need to get the “separation axes” of the polygons. To get the separation axis you need to take all the edges of the polygons and get the normal of them. Getting the edges is just taking two of the vertices and subtracting their positions.
      for example we have a triangle made up of 3 vertices. We then loop through all the vertices and in the loop we take the vertices[index] and vertices[index mod len(vertices)] and subtract them.
      We then need to normalize those edges. The edges tell use the direction of the edges from the start to the end. We need to get the direction facing away from the edge. (Ex: we have a vertical wall like | and the direction facing away is

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

      Here is some code written in lua that uses SAT to determine if two convex polygons are colliding:
      function polygonVPolygon(p1, p2) --Separating Axis Theorem here
      --get the axes
      local axes = {} --list of axes
      for i=1, #p1 do
      local edge = vectorSubtr(p1[i], p1[i%#p1 + 1])
      --note that in lua the first index in a list is 1. In languages like python you would do (i + 1)%len(p1)
      axes[#axes + 1] = vectorNormal(edge)
      end
      for i=2, #p2 do
      local edge = vectorSubtr(p2[i], p2[i%#p2 + 1])
      axes[#axes + 1] = vectorNormal(edge)
      end
      --We have all the axes. We now need to project the polygons
      local function projectPolygon(vertices, axis)
      local max = vectorDot(vertices[1], axis)
      local min = max
      for i=2, #vertices do
      local vertex = vertices[i]
      local projectedOntoAxis = vectorDot(vertex, axis)
      if projectedOntoAxis > max then
      max = projectedOntoAxis
      end
      if projectedOntoAxis < min then
      min = projectedOntoAxis
      end
      end
      return max, min
      end
      for _, axis in pairs(axes) do
      local p1max, p1min = projectPolygon(p1, axis)
      local p2max, p2min = projectPolygon(p2, axis)
      if p1min > p2max or p2min > p1max then --not colliding
      return false
      end
      end
      return true
      end
      --vector functions
      function vectorAdd(v1, v2)
      return {v1[1] + v2[1], v1[2] + v2[2]}
      end
      function vectorSubtr(v1, v2)
      return {v1[1] - v2[1], v1[2] - v2[2]}
      end
      function vectorMult(v, s)
      return {v[1] * s, v[2] * s}
      end
      function vectorNormal(v)
      local len = length(v)
      return {-v[2]/len, v[1]/len}
      end
      function vectorDot(v1, v2)
      return v1[1] * v2[1] + v1[2] * v2[2]
      end
      function length(v)
      return math.sqrt(v[1]^2 + v[2]^2)
      end
      Keep in mind that this code assumes that polygons are made up of a list of vertices list this {{x, y}, {x,y}, {x,y}}

  • @arcturusindustries1014
    @arcturusindustries1014 3 роки тому

    The HEX

  • @marekse727
    @marekse727 3 роки тому +1

    I wonder which language is good for this when you want to start

    • @MacroPixel
      @MacroPixel  3 роки тому +1

      I personally used GameMaker as a language to start with, but you unfortunately can't get a free license for it anymore. I would then say Python (+ the Pygame library) is a good way to start nowadays :)

    • @anythingcaiden
      @anythingcaiden 3 роки тому +4

      Use english this is america

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

    how do u make ur animations?

  • @Cyberlong
    @Cyberlong 3 роки тому

    But how much more heavy it is to use the movable axis one?, i know that aabb is fast, but how faster is it compared to the second one?

    • @aidenshi5178
      @aidenshi5178 3 роки тому +1

      While SAT is fast, it is still inefficient to run it all the time. Many modern physics engine use both, drawing an AABB and if those collide, using SAT to check if they are actually colliding.

    • @Cyberlong
      @Cyberlong 3 роки тому

      @@aidenshi5178 so switching dynamically is more efficient that only having SAT? Huh, interesting.

    • @aidenshi5178
      @aidenshi5178 3 роки тому +1

      @@Cyberlong Basically you use a faster, but less accurate method (AABB) do see if they might collide, and then you run a more accurate test (SAT)

    • @Cyberlong
      @Cyberlong 3 роки тому

      @@aidenshi5178 ohh, i get it now, thanks!

    • @aidenshi5178
      @aidenshi5178 3 роки тому

      No problem :)

  • @ethanyang7205
    @ethanyang7205 3 роки тому +3

    e

    • @Klaux
      @Klaux 3 роки тому

      true...

  • @trinityy-7
    @trinityy-7 3 роки тому

    hi

  • @cadmiarjw
    @cadmiarjw 3 роки тому

    im not early but im 11th

  • @CaptainBeebi
    @CaptainBeebi 12 днів тому

    "This is an informative video, however, I am an idiot"
    I feel like similar disclaimers need to be included with any sort of API documentation.

  • @yu41s
    @yu41s 3 роки тому

    hummm

  • @aeonic
    @aeonic 6 місяців тому +3

    those aren't parallel!