Collisions in Pygame - Beginner Tutorial

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

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

  • @HoRRoRlets
    @HoRRoRlets ปีที่แล้ว +31

    My Dude. I have been playing with pygame for months now. Got number of projects under my belt. I always find myself coming back to your vids for some assistance...This here, is a perfect example. Been looking for a means of determining line collisions...and lo and behold ... Russ has done it again!!
    Much appreciated man!!

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

      I have needed line collisions for a project over a year ago with pygame. I've been looking for simple line collisions since. This is a deus ex machina for my project! Russ just got a new subscriber.

  • @DineshVaidyaOfficial
    @DineshVaidyaOfficial ปีที่แล้ว +11

    Hi! Thanks for this amazing tutorial series, they are just awesome, the way you explain is really really nice. So please keep it on and continue this series on pygame. I must say that your channel is underrated but whoever will visit your channel will definitely love and follow it. Thanks once again.

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

      Thanks a lot for the kind words!

  • @SkyFly19853
    @SkyFly19853 ปีที่แล้ว +5

    Getting interesting more and more each lesson.

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

    I follow your lessons it're very interesting and easy to understand Thanks for your great job

  • @windchaser123
    @windchaser123 ปีที่แล้ว +7

    Intro 0:00
    Rectangle Collisions 0:39
    Point Collisions 6:12
    Line Collisions 8:26

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

      Nice! Thanks

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

      @@CodingWithRuss no problem, just needed to make a reference for myself. This is a fantastic tutorial, it really helped my project!

  • @Quilonis
    @Quilonis 11 หลายเดือนก่อน +4

    Small amount of likes for a really good and useful video , thanks

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

    Great video, good cadence and paceing please keep making videos. And good luck on your future projects.

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

    For the source code used in this tutorial, head over to my website: www.codingwithruss.com/pygame/top-3-collision-types-in-pygame/

  • @blautouristgm1936
    @blautouristgm1936 10 หลายเดือนก่อน +2

    huge thanks, help me a lot

    • @CodingWithRuss
      @CodingWithRuss  10 หลายเดือนก่อน +1

      Glad to hear it helped

  • @boxhead-zk7sn
    @boxhead-zk7sn ปีที่แล้ว

    guy thanks because I made it if the box1 touch's box2 it make just basically a makeshift edge grip

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

    How can I tweak the position of the hitbox rectangle relative to whatever model/ sprite I'm using? Can I do that within the library or?

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

      Yes, you can manually create a rectangle with pygame.Rect() and pass in the size you would like to use. Then you can draw your image using the rectangle's x and y coordinates. You may just need to offset it a little bit if it doesn't look right.

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

      @@CodingWithRuss Thank you. I think I get the gist. Any chance you could do a video on this, just in case? I'll play around with it until then. Cheers 😄

  • @Blinkers2007GameDev
    @Blinkers2007GameDev 10 หลายเดือนก่อน

    Hi, I need help with something.
    I have made a Space Invaders game with rect collision. The enemies and the player are not rect objects. I noticed a problem with the game: The collision ONLY works if I hit the enemies on the right corners. I am using distance as my collision but colliderrect-based collision does not work either. Is it supposed to be like that with non-rectangle objects or have I done something wrong? Thank you for your answer!

  • @albin197
    @albin197 6 หลายเดือนก่อน +2

    for some reason the "rect_1 = pygame.Rect(0, 0, 25, 25)" is giving me "'module' object is not callable" error

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

      It's pygame.rect..Rect

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

      It's pygame.rect.Rect(a,b,c,d)

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

      You need to used double brackets (())

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

      Welp too late

  • @Meysamm-xi5nv
    @Meysamm-xi5nv ปีที่แล้ว

    thank you so much , very helpful content

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

    Thank you so much :)

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

    I get collisions but I don't understand how to exactly handle them once they happen.
    I have a little space invaders game but instead of ships you shoot space rocks or they hit you and you die, but my ship can shoot, once a collision is detected I need to know how I can make that rock dissapear, I am currently just moving the rock back to the top so it looks like you just blow it up but I will need to actually just remove the rock from the game, how can I do this?

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

      @yourboizach9681
      I'm assuming you have all of your rocks in a list. I'm also assuming have a method to somehow check if the rock got hit.
      Use a for loop. Here is some example code.
      for star in stars[:]:
      if star.got_hit_by_bullet:
      stars.remove(star)

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

      @@witherhoard99 i figured it out, I needed to use .kill()
      It's a sprite group so you can't use .remove or .clear I don't think
      My game has actually advanced significantly since this post, I wish I could link it here somehow.

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

    Why define all the colors as RGBs instead of just use the abailable color presets as string? For example
    WHITE = (225, 225, 225)
    pygame.draw.rect(screen, WHITE, obstacle)
    #instead of
    pygame.draw.rect(screen, "white", obstacle)

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

      Both are valid and in some of my games I use the named colour presets. If you want to define your own colours though that aren't part of the defined list, it would make sense to create a variable so it could be reused in other parts of the game