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!!
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.
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.
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.
@@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 😄
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!
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?
@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)
@@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.
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)
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
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!!
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.
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.
Thanks a lot for the kind words!
Getting interesting more and more each lesson.
Glad to hear it!
@@CodingWithRuss
Indeed!
I follow your lessons it're very interesting and easy to understand Thanks for your great job
Intro 0:00
Rectangle Collisions 0:39
Point Collisions 6:12
Line Collisions 8:26
Nice! Thanks
@@CodingWithRuss no problem, just needed to make a reference for myself. This is a fantastic tutorial, it really helped my project!
Small amount of likes for a really good and useful video , thanks
Great video, good cadence and paceing please keep making videos. And good luck on your future projects.
Thank you!
For the source code used in this tutorial, head over to my website: www.codingwithruss.com/pygame/top-3-collision-types-in-pygame/
huge thanks, help me a lot
Glad to hear it helped
guy thanks because I made it if the box1 touch's box2 it make just basically a makeshift edge grip
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?
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.
@@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 😄
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!
for some reason the "rect_1 = pygame.Rect(0, 0, 25, 25)" is giving me "'module' object is not callable" error
It's pygame.rect..Rect
It's pygame.rect.Rect(a,b,c,d)
You need to used double brackets (())
Welp too late
thank you so much , very helpful content
Thank you so much :)
No problem :)
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?
@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)
@@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.
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)
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