Linear Collision Resolution in 2D Game Physics

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 พ.ย. 2024

ความคิดเห็น • 58

  • @Bingo901
    @Bingo901 2 ปีที่แล้ว +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  2 ปีที่แล้ว +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 2 ปีที่แล้ว +2

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

  • @vincenzopanella2705
    @vincenzopanella2705 ปีที่แล้ว +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  ปีที่แล้ว +1

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

    • @vincenzopanella2705
      @vincenzopanella2705 ปีที่แล้ว

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

    • @pikuma
      @pikuma  ปีที่แล้ว +1

      I'm from Brazil. 🙂

  • @Mong3
    @Mong3 ปีที่แล้ว +2

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

    • @pikuma
      @pikuma  ปีที่แล้ว +1

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

    • @llpBR
      @llpBR 4 หลายเดือนก่อน

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

  • @SkSafowan
    @SkSafowan 2 ปีที่แล้ว +3

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

    • @pikuma
      @pikuma  2 ปีที่แล้ว +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 ปีที่แล้ว +1

    Absolutely great video, great explanations!

  • @StarContract
    @StarContract 6 หลายเดือนก่อน +1

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

    • @pikuma
      @pikuma  6 หลายเดือนก่อน

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

    • @StarContract
      @StarContract 6 หลายเดือนก่อน

      @@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

  • @Arkensor
    @Arkensor ปีที่แล้ว +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.

  • @fabianrr
    @fabianrr 2 ปีที่แล้ว +3

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

  • @jiriblahos4051
    @jiriblahos4051 2 ปีที่แล้ว +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  2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@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.

  • @macaco_agiota
    @macaco_agiota ปีที่แล้ว +1

    Really great content! Thank you!

  • @va9if
    @va9if 2 ปีที่แล้ว +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  2 ปีที่แล้ว

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

  • @joseloeza371
    @joseloeza371 2 ปีที่แล้ว +1

    Excelent Gustavo...

    • @pikuma
      @pikuma  2 ปีที่แล้ว

      Gracias Jose! All the best. 🙂

  • @Test-iv4pm
    @Test-iv4pm 2 ปีที่แล้ว +1

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

    • @pikuma
      @pikuma  2 ปีที่แล้ว

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

  • @davidemarchese7569
    @davidemarchese7569 5 หลายเดือนก่อน +1

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

    • @pikuma
      @pikuma  5 หลายเดือนก่อน +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.

  • @halleffect5439
    @halleffect5439 2 ปีที่แล้ว

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

  • @krumss
    @krumss 2 ปีที่แล้ว

    any new video? I love your video

  • @Test-iv4pm
    @Test-iv4pm 2 ปีที่แล้ว

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

    • @Test-iv4pm
      @Test-iv4pm 2 ปีที่แล้ว +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  2 ปีที่แล้ว

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

  • @unknown-bx8my
    @unknown-bx8my 2 ปีที่แล้ว

    does apply impulse change acceleration too?

    • @pikuma
      @pikuma  2 ปีที่แล้ว +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.

  • @Midredel
    @Midredel 11 หลายเดือนก่อน

    При столкновении объектов не происходит тангенциального вращения т.к. это нарушает закон сохранения энергии. Механика, стр. 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

    • @владимиркарпов-т4ъ
      @владимиркарпов-т4ъ 6 หลายเดือนก่อน

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

  • @KrishnaSaiJonnalagedda
    @KrishnaSaiJonnalagedda 9 หลายเดือนก่อน

    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  9 หลายเดือนก่อน

      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).

    • @KrishnaSaiJonnalagedda
      @KrishnaSaiJonnalagedda 9 หลายเดือนก่อน

      ​@@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

  • @gcpezzi
    @gcpezzi 2 ปีที่แล้ว +1

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

    • @prometheusli101
      @prometheusli101 2 ปีที่แล้ว +1

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

    • @pikuma
      @pikuma  2 ปีที่แล้ว

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

    • @prometheusli101
      @prometheusli101 2 ปีที่แล้ว +1

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

    • @pikuma
      @pikuma  2 ปีที่แล้ว

      @@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 2 ปีที่แล้ว +1

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

  • @GoatsOnAParachute
    @GoatsOnAParachute 5 หลายเดือนก่อน

    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  5 หลายเดือนก่อน

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

    • @GoatsOnAParachute
      @GoatsOnAParachute 5 หลายเดือนก่อน +1

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

    • @pikuma
      @pikuma  5 หลายเดือนก่อน +1

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

  • @thomasamathew4058
    @thomasamathew4058 2 ปีที่แล้ว +1

    Did you stop YT?

    • @pikuma
      @pikuma  2 ปีที่แล้ว +1

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

    • @thomasamathew4058
      @thomasamathew4058 2 ปีที่แล้ว

      @@pikuma other content ? Your website ?

    • @pikuma
      @pikuma  2 ปีที่แล้ว +2

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

    • @thomasamathew4058
      @thomasamathew4058 2 ปีที่แล้ว

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

  • @Felis0000
    @Felis0000 2 ปีที่แล้ว

    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.