Тёмный

SFML 2.4 For Beginners - 12: Collision Detection (AABB). 

Hilze Vonck
Подписаться 4,2 тыс.
Просмотров 63 тыс.
50% 1

In this episode I will explain how to do basic AABB collision detection and basic collision response in SFML 2.4.
Watch the full playlist: ru-vid.com?list...
I thank you for watching this video!
If you want to support me, you can buy me a coffee over here: ko-fi.com/A6138PH

Опубликовано:

 

16 ноя 2016

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 169   
@GrandBenja
@GrandBenja 6 лет назад
As many people before me, I'd like to thank you for this series. Your explanations are detailed, but easy enough for even a beginner to understand. I also appreciate that you tried to show us very clean, reusable code. (As opposed to less professional "as long as it compiles, it's good enough" tutorials.) Your series may (so far) only teach the basics, but they are good, solid basics on which we can build further learning. Your personality is a big + too. The viewer can feel that you're a good person who enjoys sharing his knowledge. That's important too when you teach beginners, since a beginner may need to feel some comforting human warmth in this unknown SFML territory. You got a well deserved donation from me. Thank you, sir. :)
@yogxoth1959
@yogxoth1959 4 года назад
This is the ONLY resource on the entire internet that worked for me, I've been tearing my hair out over this for days. THANK YOU SO MUCH!
@turbo30067
@turbo30067 7 лет назад
your tutorials are the best out there. really good job. you make it so easy to follow. thanks for existing
@evanmcblevan
@evanmcblevan 2 года назад
the same: IM SUBBING
@witzur5695
@witzur5695 7 лет назад
This is the best tutorial series on YT great job.
@mudzi9433
@mudzi9433 7 лет назад
Thank you so much for this tutorial! :3 Not only did I finally make my collision work, but I also understood what I was doing C:
@t-jolt7235
@t-jolt7235 4 года назад
I have a problem with my collision where it doesnt accept player before .GetCollider(). This happens at the very end between player.Update and view.setCenter. If you know what my problem could be please tell me.
@EricZeBaws
@EricZeBaws 7 лет назад
YAY THANK YOU FOR MAKING THIS!!
@lorow2542
@lorow2542 7 лет назад
It seems so damn easy with your tutorial!
@FilipTutorials
@FilipTutorials 5 лет назад
Realy nice examples that are easy too folow and bring much programming value with them. Thanks ;)
@Jayggz
@Jayggz 7 лет назад
Great video! can't wait to see a gravity tutorial
@tomgola3
@tomgola3 2 года назад
Hey its me from earlier videos! Don't worry i didnt give up and am still plugging away! I actually feel proud i managed to make a little "game" where a character moves and shoots and learned quite a bit! now im trying to understand collision this is really tough and my next challenge. I am probably going to watch this video alot!
@greatbullet7372
@greatbullet7372 7 лет назад
i might repeat but i want more of ur stuff :D
@lva98
@lva98 7 лет назад
Nice job, thanks!
@ron0gamingplayz102
@ron0gamingplayz102 5 лет назад
Great tutorial as always Vonck! I may be asking too late now, but can you start an openGL series?
@thebeanz7838
@thebeanz7838 7 лет назад
Hi! I am trying to apply this code into my project, changing it up a bit so it runs with sprites instead of a rectangleshapes, however, when it goes into the "GetPosition" function, it is tossing an Exception thrown at error, Access violation reading location.......not entirely sure what I am doing wrong and why returning a position is giving me this
@user-vs3vp4em8z
@user-vs3vp4em8z 7 лет назад
Hey, I have a question. I need to know how can I make my character to pass through the, lets say right side of the window and appear on the left? Its really important for me.Ty
@douglasyamasaki1095
@douglasyamasaki1095 5 лет назад
i`m trying to work your code out on my project , but somehow i cant collide in both ways , only on one way. if i do platform1.checkcollision with player it works well , but if i do player.checkcollision with platform1 it doesnt work . any clue on that? tried revising everything and it looks ok.
@asm-ex1jw
@asm-ex1jw 7 лет назад
And here I am at the end of the journey, eagerly waiting for your next video. As many others here, I have a question for you: I code on a laptop, and I've noticed that CPU usage goes up by a lot (from ~10% to ~70%) when I launch the application, so my machine starts heating up real quick. Apparently, this is due to the opening of the app window, and it's just in part VS's fault: if I open the .exe in the release folder it's still at least 40% extra work on the CPU. I wonder if that's normal and if there's a way to improve the performance on the system. Thanks
@Lyoshiiro
@Lyoshiiro 7 лет назад
is it possible to use this format/lib file to make 3D AABB instead of 2D AABB? * still for opengl
@AndrewOBannon
@AndrewOBannon 7 лет назад
thanks
@johnmaquis6272
@johnmaquis6272 5 лет назад
I get an error "error: no matching function for call to 'Platform::Platform(std::nullptr_t, sf::Vector2f, sf::Vector2f)'" when creating the platforms. Help anyone please?
@bendgk123
@bendgk123 6 лет назад
Instead of push you could say inertia. Inertia is defined as how resistant an object is to any force. An object having a higher inertia would “push back” harder
@AdrianWitzil
@AdrianWitzil 6 лет назад
I did it!!!
@keithan7387
@keithan7387 2 года назад
in 14:33 i made that getCollision in my player.cpp file but it says that body is an undeclared identifier? I have even include the collision file in the h file of my player.
@RedubbledD
@RedubbledD 6 лет назад
Hello, i realy like you tutorials. You realy explain things well. but it would be nice if you could put the files online (or code). I am running into some problems when i am colliding with the platforms. When i walk to the platforms, platform 1 is moving away(without colliding), and platform 2 isnt doing anything. except when walking upstairs, then it starts blinking Could someone help?
@raidoukuzunoha9874
@raidoukuzunoha9874 3 года назад
can this 1 collision system be appliied to multiple sprites or game objects like enemies, pickups and walls as i thought this is some sort of collision parents for all objects. If so, how can i include it inside each one of them, means like do i have to declare different names of the collider for every different objects. Please let me know cuz im kinda new to sfml and also c++. T-T
@HiagoRAD
@HiagoRAD 5 лет назад
My getCollider function is not working! It has no match for Collider(body). Does anyone had the same issue?
@maxtwist3598
@maxtwist3598 7 лет назад
it doesnt works if object are moving fast?
@navaneeth6157
@navaneeth6157 6 лет назад
holy shit this is soo hard :)
@tushankhan1853
@tushankhan1853 3 года назад
How to fix redefinition in collider??
@stfoggy124
@stfoggy124 Год назад
at higher speeds you can easily glitch through the collision, does anyone know how to fix this?
@frederikja2210
@frederikja2210 7 лет назад
your thing called push in physics is named mass :D
@dafemele10
@dafemele10 7 лет назад
I get an error "Expression must be LValue" on this part: platform1.getCollider().chechCollision(player.getCollider(), 0.0f); ^
@Pedro62ful
@Pedro62ful 6 лет назад
I got the same error, did you fix yours?
@invis7476
@invis7476 6 лет назад
Same here, not sure what I'm doing wrong.
@blueseelen8047
@blueseelen8047 6 лет назад
So I quess we will never get an answer what's wrong :(
@TheCarljeff
@TheCarljeff 6 лет назад
Hey, I was just having this same problem and I fixed it by removing the & in the CheckCollision parameters. So instead of CheckCollision(Collider &other, float push), it is CheckCollision(Collider other, float push). (make sure to modifyt the header as well)
@niallmaple
@niallmaple 6 лет назад
It needs you to store the players collider before passing it by reference, so Collider col = player.GetCollider(); , then pass col in. Since the getcollider returns a Collider, not a Collider* or & so as soon as that finishes it goes out of scope, meaning the pass by reference will be referencing bad memory. It's usually more efficient to pass by const reference for somewhat complicated data structures (aka anything thats not a standard int or float etc) but if within the function that is taking it, wants to modify that type - it cannot be const.
@vunguyenhoang3075
@vunguyenhoang3075 5 лет назад
i think "push" variable can be rename to "resistance'
@_simobr
@_simobr 3 года назад
When I write player.getCollider() in the CheckCollision method it tells me this: initial value of reference to non-const must be an lvalue 49 cannot convert argument 1 from 'Collider' to 'Collider &' Can anyone tell me why?
@aayushkarki108
@aayushkarki108 3 года назад
did you fix it? I got the same thing
@_simobr
@_simobr 3 года назад
@@aayushkarki108 nope, I've done the collider method in the class to resolve, but it isn't very correct
@aayushkarki108
@aayushkarki108 3 года назад
@@_simobr is it possible for you to share the resolved code?
@_simobr
@_simobr 3 года назад
@@aayushkarki108 meme its not properly solved
@eduardomora6028
@eduardomora6028 3 года назад
I got this error too, I don't know how he didn't get this. The problem is that in the getCollider function you are returning a temporary Collider object and you have a reference to Collider in CheckCollision function, you are trying to bind a non-const reference to a temporary object which is not allowed. What I did was create an empty default constructor for Collider class, create private default Collider objects in the platform class and player classes, then in the getCollider function I set these objects to Collider(body) and return that value. Lastly, I have the type of getCollider be Collider& (reference to collider object) instead of Collider. Now when you use pass in player.getCollider() in the CheckCollision method you are actually passing a reference to a non-temporary Collider object. There might be a shorter way to bypass this issue but this is what worked for me.
@PleaseWait...
@PleaseWait... 3 года назад
whats the point of (1.0f - push) ????
@koraykahraman9031
@koraykahraman9031 Год назад
Please keep the tutorial videos coming
@shiwanggupta8608
@shiwanggupta8608 6 лет назад
I have done exactly what is shown in the video but the platform is not moving. I tried writing platform1.GetCollider().Move(0.1f,0.0f); directly in my main file but still my platform isn't moving. Can anyone think of any mistake that I might be doing? I have already checked the video once again and haven't found any mistake
@eneszeqiri3364
@eneszeqiri3364 5 лет назад
samee! ;(
@ron0gamingplayz102
@ron0gamingplayz102 5 лет назад
8:29 Hilze is now an evil eyed sorcerer
@EricZeBaws
@EricZeBaws 7 лет назад
Does it have to be a perfect square or would a rectangle work
@HilzeVonck
@HilzeVonck 7 лет назад
+EricZeBaws The collider does not have to be a perfect square.
@EricZeBaws
@EricZeBaws 7 лет назад
okay
@ron0gamingplayz102
@ron0gamingplayz102 5 лет назад
Hello, my Player keeps moving left or right through the screen at an absurdly high speed. Any solution?
@Welniukstele
@Welniukstele 5 лет назад
Please tell me you sorted it out, and can share how, because I'm having the same problem, but it's either moving downwards or upwards. :D
@ghostly_zsh9609
@ghostly_zsh9609 4 года назад
I believe that issue is because you aren't multiplying by deltaTime.
@parthrupareliya625
@parthrupareliya625 5 лет назад
can You please send me the code of player.h where you returns the collider of body. because i got an error that cannot bind non-constant value reference of type 'Collider&' to a reverse Type Collider.
@HilzeVonck
@HilzeVonck 5 лет назад
This has something to do with the vs2017 and vs2019 compiler. With the vs2015 compiler you were able to directly use a returned copy as a constant reference, but you are not allowed to do this anymore with the vs2017 and vs2019 compilers. To fix this you simply have to store the collider in a local variable first and then pass that collider into the function, or change the function so it takes a collider instead of a constant reference to a collider.
@parthrupareliya625
@parthrupareliya625 5 лет назад
@@HilzeVonck actually i am compiling this project using latest version of gcc compiler.
@dreamhollow
@dreamhollow 9 месяцев назад
@@HilzeVonck I haven't quite figured out how to store the Collider inside of a variable, could you explain what you mean please?
@rexy_mirror1225
@rexy_mirror1225 6 лет назад
Hello good sir! So far your tutorial videos have been fantastic. However, I encountered an error on the main.cpp. The player in platform1.GetCollider().CheckCollision(player.GetCollider(), 0.0f); platform2.GetCollider().CheckCollision(player.GetCollider(), 1.0f); gives an error: initial value of reference to non-const must be Ivalue. Do you know how I can fix it?
@teamfortress2ful
@teamfortress2ful 5 лет назад
me too, i don't now how fix ;(
@teamfortress2ful
@teamfortress2ful 5 лет назад
see the comentary of Brian, fixed here
@craig15murdoch
@craig15murdoch 5 лет назад
@@teamfortress2ful Who is Brian?
@camerontelford7667
@camerontelford7667 2 года назад
YOU HAVE TO TAKE & OUT OF collision & other, float push IN COLLISION.CPP AND COLLISON.H
@soliderarmatang5664
@soliderarmatang5664 2 года назад
@@camerontelford7667 Thank you so much!!!!
@fanut3599
@fanut3599 6 лет назад
error: no matching function for call to 'Collider::CheckCollision(Collider, float)' anybody else had this problem? :(
@Esteban3999
@Esteban3999 7 лет назад
error: no matching function for call to 'Collider::CheckCollision(Collider, float)'| on platform1.GetCollider().CheckCollision(player.GetCollider(), 0.0f); same for platform2 What might be the reason? Anyone?
@orocimarosay1447
@orocimarosay1447 6 лет назад
same
@lukalazic7999
@lukalazic7999 6 лет назад
Hey did you fix this problem?
@mr.lowpoly3882
@mr.lowpoly3882 6 лет назад
Hey.. For all who have the same problem, Here is the simply solution: ..... case sf::Event::Resize: ResizeView(window, view); break; } } Collider playerCollRect = player.GetCollider(); // (or) auto playerCollRect = player.GetCollider(); player.Update(deltaTime); platform1.GetCollider().checkCollision(playerCollRect, 0.5f); platform2.GetCollider().checkCollision(playerCollRect, 0.5f) ----------------------------------------------------- I hope i could help.. Nice Tutorials Hilze Vonck
@chez-wren
@chez-wren 6 лет назад
@Mr.Lowpoly Hey thanks a lot man! Really needed this for my project. I also have a correction though: you spelt "CollRect" wrong on the platform1 and platform2 lines
@mr.lowpoly3882
@mr.lowpoly3882 6 лет назад
@Chez Boyz Oh yes sorry .. I changed it, thanks
@KKr0lik
@KKr0lik 7 лет назад
I walk by the square, and its not moving. 0 errors or warnigs. whats wrong?
@traveler2158
@traveler2158 7 лет назад
Maybe you should check if you are passing the body in the Collider class by a reference.
@leonisadonis
@leonisadonis 2 года назад
ATTENTION EVERYONE WHO USED A LIST AND A FUNCTION INSTEAD OF CLASSES if you had a list that you go throw with a for loop in a function to check for each individual tile then when you collide do break; or its gonna continue to loop after collision has been detected and set collision to false thus fucking it up but I recommend if you are gonna use a functions make it a bool copy the code then in the update set isColliding = collisionFunc(tiles) (or however you called them) and everything is gonna be fine
@estar500
@estar500 6 лет назад
I keep getting the error 'bool Collider::checkCollider(Collider &,float)': cannot convert argument 1 from 'Collider' to 'Collider &' At the very end, I've tried re watching the video multiple times but the code seems to be fine, anybody know what is going wrong here?
@AdrianWitzil
@AdrianWitzil 6 лет назад
Hey. I got the same error. Did you manage to resolve it?
@brianmontgomery6502
@brianmontgomery6502 6 лет назад
I've got this one too... If I find a solution I'll post it
@brianmontgomery6502
@brianmontgomery6502 6 лет назад
Okay the solution I found was to put this line before we check collisions between (platform1 and player) and (platform2 and player in main.cpp: 'Collision (name of your Collider member) = player.getCollider(); After that, just replace player.getCollider with (name of your Collider member) in both checkCollision calls that follow
@brianmontgomery6502
@brianmontgomery6502 6 лет назад
As far as I can tell, the compiler just didn't want us to use a member function for this variable. If anyone has a better explanation, I would love to hear it.
@njsfryj
@njsfryj 6 лет назад
Not a solution, but I did this tutorial a while back on VS community 2015, and the code worked exactly as is, I am redoing it now to get back into SFML with VS community 2017, and I get this exact same error. So, perhaps it is something weird in the newest iteration of the compiler. And your solution did work for me.
@fahdv2597
@fahdv2597 5 лет назад
Bro how did you color code visual studio?
@ModerateDev
@ModerateDev 5 лет назад
there's a bunch of tuts on YT
@edgar5686
@edgar5686 5 лет назад
A better name for the variable "push" would be "movability", for example since a wall is not movable then you have a movability of 0.
@mort0303
@mort0303 5 лет назад
Why isn't it a bool if it's always going to be either 1 or 0?
@edgar5686
@edgar5686 5 лет назад
@@mort0303 it is not always going to be 1 or 0.. The case can happen that it is for example a heavy box and you want the push to be around 0.8 or so..
@mort0303
@mort0303 5 лет назад
Edgar ah, ok. thank you
@EricZeBaws
@EricZeBaws 7 лет назад
Sorry I have one more question, How do you check a border in sfml. Ex If an object is touching the border it will do something
@HilzeVonck
@HilzeVonck 7 лет назад
+EricZeBaws do you mean the border of the screen?
@EricZeBaws
@EricZeBaws 7 лет назад
Yes
@HilzeVonck
@HilzeVonck 7 лет назад
Here you go, this function will check if a collider touches the border of a view. bool TouchesViewBorder(Collider collider, sf::View view) { sf::Vector2f colliderHalfSize = collider.GetHalfSize(); sf::Vector2f colliderPosition = collider.GetPosition(); sf::Vector2f viewHalfSize = view.getSize() / 2.0f; sf::Vector2f viewPosition = view.getCenter(); float rdx = colliderPosition.x - viewPosition.x; float rdy = colliderPosition.y - viewPosition.y; float dx = abs(rdx) - (viewHalfSize.x - colliderHalfSize.x); float dy = abs(rdy) - (viewHalfSize.y - colliderHalfSize.y); if ((dx < colliderHalfSize.x * 2.0f && dx > 0.0f) || (dy < colliderHalfSize.y * 2.0f && dy > 0.0f)) { return true; } return false; } As you can see it looks almost exactly the same as the collision code for checking if two colliders are colliding. That is because a view also has a center position and a size. The only thing that really changed is the if statement at the end. This if statement consists out of two parts: (dx < colliderHalfSize.x * 2.0f && dx > 0.0f) and (dy < colliderHalfSize.y * 2.0f && dy > 0.0f). both of these parts basically do the same thing but one of them checks the collision on the x axis and the other one on the y axis. let's take one of these parts and see what it does. The first part (dx < colliderHalfSize.x * 2.0f) basically checks if the collider is within a certain range from the border (inwards), we need to multiply the halfSize by two because we need the full size for this calculation. The second part (dx > 0.0f) basically checks if the rectangle is within a certain range from the border (outwards). So the first part checks the collision for the left and top side of the collider and the second part checks the collision for the right and bottom part of the collider. The reason that they are separated by an or ( || ) is because we want this statement to be true whenever the collider is colliding with one of the sides of the view, and not just the corners.
@EricZeBaws
@EricZeBaws 7 лет назад
Thanks so much!!
@thewhiteprogrammer9633
@thewhiteprogrammer9633 2 года назад
Collsion GetCollider() { return Collsion(shape); there is a error coming collsion.h is not inaccesbile
@elijahandrushenko6313
@elijahandrushenko6313 7 лет назад
Can you do a tutorial on gravity, so that when you jump you will fall down and so that standing on blocks matters otherwise you will fall through the screen.
@HilzeVonck
@HilzeVonck 7 лет назад
+Elijah Andrushenko Yeah, that is going to be the topic of the next video. :)
@lorow2542
@lorow2542 7 лет назад
When we should expect it? :D
@HilzeVonck
@HilzeVonck 7 лет назад
+SmykuPyka As soon as possible. I don't have any time to make an episode right now, but I'll probably have some time next week.
@dreamhollow
@dreamhollow 10 месяцев назад
I like this, but it's a lot more difficult to get to work with smart pointers.
@richardlighthouse5328
@richardlighthouse5328 7 лет назад
Please I need missing Clip!!!!!!!!!!!!!!!!!!!!!!
@sc5shout
@sc5shout 6 лет назад
Im actually more confused then before. You're doing with the centers, others with some shit like min and max and some with x, y, w and h...
@azaria_phd
@azaria_phd 2 года назад
10:35 reminder that std::clamp() exists too.
@maciejstefanski1652
@maciejstefanski1652 4 года назад
Hey i have an error C2664 "bool Collider :: CheckCollision (Collider &, float)": it is not possible to convert argument 1 from "Collider" to "Collider &"
@maciejstefanski1652
@maciejstefanski1652 4 года назад
Please really help me i wanna make the game but i cant
@HilzeVonck
@HilzeVonck 4 года назад
Hey, the problem is that it is trying to get a reference to an object that isn't defined anywhere. The solution is to simply store the result of the getcollider function and use that variable as an input for the checkcollision function. This is an lvalue vs rvalue issue. vs2015 didn't see this as an issue, but since vs2017 the compiler started to treat this as an error. I hope this helps
@maciejstefanski1652
@maciejstefanski1652 4 года назад
@@HilzeVonck i love u Man. Thanks for fast response. You made mine Day better 😀
@maciejstefanski1652
@maciejstefanski1652 4 года назад
@@HilzeVonck anyway i am new and i work at sfml like 1 hours can u tell me how can i use code to do it and where should i put it please. Still thanks a lot dude
@maciejstefanski1652
@maciejstefanski1652 4 года назад
@@HilzeVonck i am 14years So i am bad xD
@johnlight-knight8060
@johnlight-knight8060 4 года назад
I didn't understand the init-list (body(body)) but I will try to understand. :D
@boenaman4154
@boenaman4154 4 года назад
What this means is that the private variable body, will be initialized by the parameter body which is given by the constructor.
@TheDorkol5
@TheDorkol5 2 года назад
would you happen to know of a way to write *(simple)* non OOP no structs nothing, just bare bones code. of aabb response of 2 regular rectangles. or point me in the right direction? i am desperate. ive spent hours and hours looking for a simple implementation that i can read, i just want to a solid square!!!!!! why is this so hard to find!!!!!!!!!!!!!!!!!. im sure its not ideal but its the only way i can understand it. so many tutorials. or rather always have the starting ccordinates as something crazy like "entity.x.whatever.idontcare = delta.whatever.why?"
@HilzeVonck
@HilzeVonck 2 года назад
You can use the same code as is in the final check collision method. Just also pass in the position for the first aabb as a reference the size of the first aabb, the position of the second aabb as a reference and the size of the second aabb. It shouldn't be hard to convert this to a simple, c like function.
@TheDorkol5
@TheDorkol5 2 года назад
@@HilzeVonck converting it is the problem I just wanna *(see)* an example so that I know how it works. Everything being in objects makes it way to hard to pick apart. Also I'm asking in every RU-vid video about aabb resolution.
@Herovy070
@Herovy070 2 года назад
@ It could look something like this. (keep in mind that I just wrote the code and did not test it, so there might be some small syntax errors) The functionality of the function stays the same, the only thing that I changed is that we now are passing the positions and half sizes in directly, and we are also modifying these positions directly. Just make sure that the position that you pass in is the center of the AABB, and the size is half of the total size of the AABB. bool CheckCollision(sf::Vector2f& thisPosition, sf::Vector2f thisHalfSize, sf::Vector2f& otherPosition, sf::Vector2f otherHalfSize, float push) { float deltaX = otherPosition.x - thisPosition.x; float deltaY = otherPosition.y - thisPosition.y; float intersectX = abs(deltaX) - (otherHalfSize.x + thisHalfSize.x); float intersectY = abs(deltaY) - (otherHalfSize.y + thisHalfSize.y); if (intersectX < 0.0f && intersectY < 0.0f) { push = std::min(std::max(push, 0.0f), 1.0f); if (intersectX > intersectY) { if (deltaX > 0.0f) { thisPosition.x += intersectX * (1.0f - push); otherPosition.x -= intersectX * push; } else { thisPosition.x -= intersectX * (1.0f - push); otherPosition.x += intersectX * push; } } else { if (deltaY > 0.0f) { thisPosition.x += intersectY * (1.0f - push); otherPosition.x -= intersectY * push; } else { thisPosition.x -= intersectY * (1.0f - push); otherPosition.x += intersectY * push; } } } return false; }
@TheDorkol5
@TheDorkol5 2 года назад
@@Herovy070 wow to be honest this is way more than I could have asked for thank you I'll check it out when I get home. I appreciate it. I'm gonna go ahead and give you a like and a sub
@anonymousgaming911
@anonymousgaming911 5 лет назад
Delta is called Δ in Greek Its the letter D
@bondjovi4595
@bondjovi4595 Год назад
Redraw Relocate
@ThePlayerNotJump1
@ThePlayerNotJump1 7 лет назад
You do know that, SFML has functionality to detect collisions right?
@mistermaddock
@mistermaddock 7 лет назад
Frixoe i
@thewhiteprogrammer9633
@thewhiteprogrammer9633 2 года назад
bruh he is detecting aabb to do the tile collsion
@tundrummax6221
@tundrummax6221 5 лет назад
will this only ever work for squares? will it ever work for rectangles?
@tundrummax6221
@tundrummax6221 5 лет назад
Nevermind, I can see that it works.
@Donaldbeebi
@Donaldbeebi 3 года назад
this guy reminds me of pewdiepie lmao
@ahoiioha
@ahoiioha 7 лет назад
Hey, first, its a good tutorial, thank you. But could you pleaseupload your code to github or something else? I'm geting two errors in the code for this two lines: platform1.GetColider().CheckCollision(player.GetCollider(), 0.0f); platform2.GetColider().CheckCollision(player.GetCollider(), 1.0f); Invalid arguments ' Candidates are: bool CheckCollision(Collider &, float) ' Invalid arguments ' Candidates are: bool CheckCollision(Collider &, float) ' invalid initialization of non-const reference of type 'Collider&' from an rvalue of type 'Collider' invalid initialization of non-const reference of type 'Collider&' from an rvalue of type 'Collider' Can anybody help?
@Herovy070
@Herovy070 7 лет назад
I have actually been working on rewriting all the code to upload to the site that I am building all day. All of the source code for this video should be up there. Here is the link: lucrifi.com/index.php/24-sfml-2-4-for-beginners-12-collision-detection-aabb?start=1. As a note though. The site is not yet finished at all, so if something is wrong or if something does not work, It'll be fixed as soon as possible. I think that the problem is either in the player's GetCollider() function or in the variables that you are passing into the CheckCollision() function. Make sure that the player's GetCollider() is NOT returning a reference to a collider. And make sure that the CheckCollision() DOES have references to the collider (both in the .h and the .cpp).
@HilzeVonck
@HilzeVonck 7 лет назад
+Herovy070 whoops, I replied with my secondary YT account. Herovy070s reply is mine.
@ahoiioha
@ahoiioha 7 лет назад
Thanks for the quick respons, I checked your link and checked your code with this page www.qualidator.com/WQM/de/Tools/TextDiff.aspx, I could not see any significant difference to my code, This is the play's GetCollider() Collider GetCollider() { return Collider(body);} and this is CheckCollision() in .h bool CheckCollision(Collider& other, float push); in .cpp bool Collider::CheckCollision(Collider & other, float push){
@rasen_nax
@rasen_nax 7 лет назад
Hi,Thx for this great tutorial! I'm using code::block and got the same error even after copying all files from lucrifi.com/index.php/24-sfml-2-4-for-beginners-12-collision-detection-aabb?start=1. I've solved it by using bool CheckCollision(Collider , float).
@muffinspuffinsEE
@muffinspuffinsEE 7 лет назад
Please help! I have the same issue, or if there is anyone else who has a fix for that matter.
@christiancarter255
@christiancarter255 Год назад
It's not compiling, and it's telling me: "initial value of reference to non-const must be an lvalue" and "'bool Collider::CheckCollision(Collider &, float)': cannot convert argument 1 from 'Collider' to 'Collider &'" :(
@christiancarter255
@christiancarter255 Год назад
I figured it out.
@mr.fantasy1
@mr.fantasy1 6 месяцев назад
how @@christiancarter255
@woff5
@woff5 2 месяца назад
@@christiancarter255 what was wrong plz tell us
@christiancarter255
@christiancarter255 2 месяца назад
@@woff5 I wish I remembered 😔😭
@woff5
@woff5 2 месяца назад
@@christiancarter255 no worries someone had the same problem and had the awnser
@ricanteja
@ricanteja 7 лет назад
Great video but I got a question. Why didn't you just use self.getGlobalBounds().intersects(other.getGlobalBounds()); ? Much simpler for AABB IMHO
@AdrianWitzil
@AdrianWitzil 6 лет назад
Hey Ricardo, I got an error. Can you give me a hand?
@mosesvalentin1600
@mosesvalentin1600 5 лет назад
yeah that's what I thought too
@yagami1160
@yagami1160 Год назад
why was I making this whole lot of stupid stuff
@vedatemin7639
@vedatemin7639 2 года назад
platfom1.GetCollider().CheckCollision(player.GetCollider(), 0.0f); platfom2.GetCollider().CheckCollision(player.GetCollider(), 1.0f); player gives an error in my code?
@woff5
@woff5 2 месяца назад
yeah same did you figure it out
@Bingo901
@Bingo901 2 года назад
Thank you for all the work that you put into these videos, I learned a lot and really became fond of sfml it feels more natural than SDL2.
Далее
SFML 2.4 For Beginners - 13: Jumping.
16:37
Просмотров 44 тыс.
We made Vampire Survivors BUT in 10 Lines of Code
7:08
Вопрос Ребром - Субо
49:41
Просмотров 1,4 млн
▼КОРОЛЬ СОЖРАЛ ВСЕХ 👑🍗
29:48
Просмотров 412 тыс.
Ray Tracing with Bounding Volume Hierarchies
15:40
Просмотров 2,4 тыс.
Jbump AABB Collision Detection and Physics
12:52
Просмотров 2,2 тыс.
14. C++ AABB Collision and Movement - Celeste Clone
18:36
One year of my C++ SFML journey
5:39
Просмотров 410 тыс.
How Collisions Work in Games
5:54
Просмотров 199 тыс.