Linear Collision Resolution in 2D Game Physics

Sdílet
Vložit
  • čas přidán 11. 09. 2024

Komentáře • 58

  • @Bingo901
    @Bingo901 Před 2 lety +15

    I’m taking your course on 2d physics, it is just fascinating, makes me love coding and math more and more. Would love to see more of this content.

    • @pikuma
      @pikuma  Před 2 lety +2

      Thank you for the kind words. The only way I can continue to make more videos is if more students find out about pikuma.
      Every help in spreading the word helps. 🙂👍

  • @unknown-bx8my
    @unknown-bx8my Před rokem +2

    this is the best game physiscs video i have ever seen.

  • @vincenzopanella2705
    @vincenzopanella2705 Před rokem +1

    I bought his course on 2d physics and it is the best online course i have ever taken, he goes deep into advanced physics, all the other stuff i have read online is incorrect and incomplete, buy his course and you won't regret it.

    • @pikuma
      @pikuma  Před rokem +1

      Thank you for the kibd words, Vicenzo! It also helps that the topic is extremely fun. 🙂

    • @vincenzopanella2705
      @vincenzopanella2705 Před rokem

      Hello Gustavo!, are you italian too ??? cannot wait to see your next 3d physics engien programming

    • @pikuma
      @pikuma  Před rokem +1

      I'm from Brazil. 🙂

  • @Mong3
    @Mong3 Před rokem +2

    Akita brought me here! So nice to discover your content.

    • @pikuma
      @pikuma  Před rokem +1

      Grande Akita. Ajudando os canais menores. 😄 Abração e obrigado pelo follow.

    • @llpBR
      @llpBR Před 2 měsíci

      Aha! Eu tinha certeza que vc é brasileiro pelo sotaque! Cheguei aqui aleatoriamente pq comecei a brincar de fazer jogo esse ano

  • @fabianrr
    @fabianrr Před 2 lety +3

    Muy bueno, me compre el de Raycasting Programming with C 👌

  • @SkSafowan
    @SkSafowan Před 2 lety +3

    Great content really, you should use some audio software to clear out the walkie sound

    • @pikuma
      @pikuma  Před 2 lety +1

      Thank you. I'll eventually learn how to do this video thing. 🙂
      I'll look into it. Let me know if you have any suggestions of software that does that.

  • @danielzachtec
    @danielzachtec Před rokem +1

    Absolutely great video, great explanations!

  • @Arkensor
    @Arkensor Před rokem +2

    Hello, thank you for the good explaination. I have one question and that is that the final resolve does not seem to take into account HOW MUCH overlap there was between the objects. The calculation result seems to be the same no matter if they barely touch or one object penetrates deep into the other. Can this be ignored and if so why? I would normally imagine that you would want to make sure that at the end of a discrete time simulation step the two objects are not colliding anymore and have their final velocity for the next simulation tick to then move away from each other.

  • @macaco_agiota
    @macaco_agiota Před rokem +1

    Really great content! Thank you!

  • @va9if
    @va9if Před 2 lety +1

    You went so far back to the relative velocity explanation. It took a bit long cuz if this but still is nice

    • @pikuma
      @pikuma  Před 2 lety

      I know. Just need to make sure we don't leave anyone behind. 🙂

  • @StarContract
    @StarContract Před 4 měsíci +1

    Very nice,
    I wonder if you also made a video about collision resolution that involves angular momentum

    • @pikuma
      @pikuma  Před 4 měsíci

      Absolutely! 🙂 It's all included in the lectures.
      🔗pikuma.com/courses/game-physics-engine-programming

    • @StarContract
      @StarContract Před 4 měsíci

      @@pikuma nice, I just finished watching your verlet integration video.
      I have a question -
      I am implementing a 2d physics engine and I want to support multiple constraints like springs, to enable exotic features like soft bodies. Does your course go over topics such as a system of constraints, verlet integration etc?
      If it does, I'll buy it right now

  • @jiriblahos4051
    @jiriblahos4051 Před 2 lety +4

    Great stuff! I would have one question though. Isn't it possible that you resolve a collision, then move your objects in one time step, and they are still in contact after that? Since the game runs in discrete time steps and you need to get an overlap to detect the collision. That could cause you to resolve the same collision twice which would be nonsense I suppose.

    • @pikuma
      @pikuma  Před 2 lety +4

      That is a great question! You see, you are absolutely correct. In this video I focused on the "detection" part of the collision, and not on the "resolution." To resolve the collision we have many different techniques; some engines perform a position correction to first offset the bodies away from each other so they don't collide anymore, and we also have engines that apply 'impulses' to both bodies to simulate a proper collision resolution.
      These techniques have pros and cons. Just changing the position of two colliding bodies might be okay when we only have two bodies, but what happens when we have multiple bodies touching each other (fixing one collision and offsetting the bodies might cause other collisions with other neighboring bodies). You see, it's a tricky game.
      What most engines do is to work with "constraints", and solve both position and velocity constraints of the system. The engines either solve a huge system of equations to account for all the bodies, or solve one collision at a time but iterate to get closer to the best solution each pass of the iteration.
      I'm sorry, your question might look simple but it's the core of super complex discussions in game engines. There are many methods that engines use to solve that.
      As always, if you're interested to really dig deeper, check out my 2D physics course at pikuma.com. :)

    • @jiriblahos4051
      @jiriblahos4051 Před 2 lety

      @@pikuma Thanks for a great answer! I realise that it is a complex topic for sure. One idea that I had was that you could add condition to collision detection that the bodies need to be moving towards each other along the normal vector. So after you resolve the collision the first time, the bodies start moving away from each other so the next step you wouldn't detect any collision even if the overlap still exists. But I haven't thought it through entirely, it could have some issues.

  • @joseloeza371
    @joseloeza371 Před 2 lety +1

    Excelent Gustavo...

    • @pikuma
      @pikuma  Před 2 lety

      Gracias Jose! All the best. 🙂

  • @davidemarchese7569
    @davidemarchese7569 Před 3 měsíci +1

    if the objects in my scene are subject to acceleration will the method still work?

    • @pikuma
      @pikuma  Před 3 měsíci +1

      Absolutely. All the forces of your system will result in an acceleration, which will change their velocities, which will then change their position. Collision check happens after the pisition was updated and the resolution proceeds from there.

  • @gcpezzi
    @gcpezzi Před 2 lety +1

    If anyone wants the snippet of code that I used, feel free to ask here in the comments. :)

    • @prometheusli101
      @prometheusli101 Před 2 lety +1

      i dont use C++,just learn concept in this channel

    • @pikuma
      @pikuma  Před 2 lety

      @@prometheusli101 That's a good approach. :) This should be valuable regardless of the language you use. What's your language of choice?

    • @prometheusli101
      @prometheusli101 Před 2 lety +1

      @@pikuma dart, seems nobody teach this by using dart,so i can only choose this approach

    • @pikuma
      @pikuma  Před 2 lety

      @@prometheusli101 True! Dart is a great language, I believe Bob Nystrom works in the Dart team. Meanwhile, I'll try to keep things as language-agnostic as possible. All the best.

    • @prometheusli101
      @prometheusli101 Před 2 lety +1

      @@pikuma you needn't change any thing,good enough already,thanks for your work

  • @halleffect5439
    @halleffect5439 Před 2 lety

    So the parallel component of the relative velocity is not affected, if i am right?

  • @user-ji1gf6vv8u
    @user-ji1gf6vv8u Před 7 měsíci

    for some reason in my implementation of this code causes the objects to get energy out of nowhere over time, do you have a solution to this

    • @pikuma
      @pikuma  Před 7 měsíci

      This is probably connected to the type of integration you're using for the simulation of movement. Can you kindly check my video on Verlet integration please? There, I mention some different integrations that instead of gaining energy end up losing energy over time (but a lot slower).

    • @user-ji1gf6vv8u
      @user-ji1gf6vv8u Před 7 měsíci

      ​@@pikumaok I have shifted to verlet integration but the problem very much remains, when I put project the bodies directly at one another along the X or Y axis or 45 degrees with respect to the one another the program runs as expected but when subjected to more unusual angles extra momentum is seen among the bodies

  • @Test-iv4pm
    @Test-iv4pm Před 2 lety +1

    Do you have a lesson like this for polygons / with rotations?

    • @pikuma
      @pikuma  Před 2 lety

      Sure. I go over 2D polygon collision detection and resolution in the course (2D convex polygos).

  • @krumss
    @krumss Před 2 lety

    any new video? I love your video

  • @Test-iv4pm
    @Test-iv4pm Před 2 lety

    How do you know which object (A or B) gets the +J and which one gets the -J?

    • @Test-iv4pm
      @Test-iv4pm Před 2 lety +3

      Actually I am thinking now that it doesn't matter, because if A and B labels are swapped, the sign of the relative velocity also swaps

    • @pikuma
      @pikuma  Před 2 lety

      @@Test-iv4pm Correct. The magbitude of the impulse should be the same, just flipped.

  • @unknown-bx8my
    @unknown-bx8my Před rokem

    does apply impulse change acceleration too?

    • @pikuma
      @pikuma  Před rokem +1

      No. Acceleration happens when there are forces being applied to an object. Applying an impulse, in our simplified version of things, is basically just an instantaneous change in velocity.

  • @GoatsOnAParachute
    @GoatsOnAParachute Před 3 měsíci

    This video is missing a huge component: how to calculate the collision normal n. For spheres, I think this is the difference vector between the two centers of the spheres at time of collision.

    • @pikuma
      @pikuma  Před 3 měsíci

      This is part of collision detection and collision information, which is shape-dependent.

    • @GoatsOnAParachute
      @GoatsOnAParachute Před 3 měsíci +1

      @pikuma But for the spheres example in this video, it's what I said above correct?

    • @pikuma
      @pikuma  Před 3 měsíci +1

      @@GoatsOnAParachute Yes. Spheres are easy to detect and find the collision info. 🙂👍

  • @Midredel
    @Midredel Před 9 měsíci

    При столкновении объектов не происходит тангенциального вращения т.к. это нарушает закон сохранения энергии. Механика, стр. 162, Сивухин Д.В., 2005
    When objects collide, tangential rotation does not occur because this violates the law of conservation of energy. Mechanics, p. 162, Sivukhin D.V., 2005

    • @user-bc9tu6om8b
      @user-bc9tu6om8b Před 4 měsíci

      Столкновение между абсолютно упругими там расписывается, а не как в физ движке

  • @Felis0000
    @Felis0000 Před rokem

    I'm unable to contact you on the messenger ;(
    I promise I won't inconvenience you, again.
    I may be tiresome to you at this point, I apologize for this state. I wish to learn C++ game engine and physics engine development more than anything else right now, and I think my request justifies by the unfair conversion rate considering our economical value, trust me most of the people are impoverished here due to the bajillion population count and other platforms offering things at reduced cost after conversion. Sir, please let me know what you consider.

  • @thomasamathew4058
    @thomasamathew4058 Před 2 lety +1

    Did you stop YT?

    • @pikuma
      @pikuma  Před 2 lety +1

      No, I'll still post videos here every once in a while. But since CZcams is not a great platform for structured learning, I'm mosrly focused on other content.

    • @thomasamathew4058
      @thomasamathew4058 Před 2 lety

      @@pikuma other content ? Your website ?

    • @pikuma
      @pikuma  Před 2 lety +2

      @@thomasamathew4058 Well, yes. But my lectures for the university as well. 😬

    • @thomasamathew4058
      @thomasamathew4058 Před 2 lety

      @@pikuma oh okay. I checked out your course and it is everything I wanted..I'll buy it soon.