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

Поділитися
Вставка
  • Опубліковано 31 жов 2024

КОМЕНТАРІ • 172

  • @GrandBenja
    @GrandBenja 7 років тому +42

    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 роки тому +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 8 років тому +34

    your tutorials are the best out there. really good job. you make it so easy to follow. thanks for existing

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

  • @mudzi9433
    @mudzi9433 7 років тому +3

    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 5 років тому +8

    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.

  • @bendgk123
    @bendgk123 6 років тому +2

    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

  • @PflanzenChirurg
    @PflanzenChirurg 8 років тому +8

    i might repeat but i want more of ur stuff :D

  • @lorow2542
    @lorow2542 8 років тому +8

    It seems so damn easy with your tutorial!

  • @quinn7630
    @quinn7630 Місяць тому

    As of 2.5.1 the coordinates systems is a bit different so if the colliders go crazy after touching, try inverting the ">" on the if statements in the checkCollision method
    I think its because the Y axis becomes positive when tou go down and negative if you go up in the lasts updates. Idk why i also had to invert the X axis tho, i think that one is still normal

  • @tomgola3
    @tomgola3 3 роки тому

    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!

  • @dafemele10
    @dafemele10 7 років тому +14

    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 років тому +8

      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 років тому +3

      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.

  • @rexy_mirror1225
    @rexy_mirror1225 6 років тому +8

    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?

  • @witzur5695
    @witzur5695 7 років тому

    This is the best tutorial series on YT great job.

  • @frederikja2210
    @frederikja2210 7 років тому +5

    your thing called push in physics is named mass :D

  • @Jayggz
    @Jayggz 7 років тому

    Great video! can't wait to see a gravity tutorial

  • @EricZeBaws
    @EricZeBaws 8 років тому +3

    YAY THANK YOU FOR MAKING THIS!!

  • @ron0gamingplayz102
    @ron0gamingplayz102 5 років тому +2

    Great tutorial as always Vonck!
    I may be asking too late now, but can you start an openGL series?

  • @FilipTutorials
    @FilipTutorials 5 років тому

    Realy nice examples that are easy too folow and bring much programming value with them.
    Thanks ;)

  • @_simobr
    @_simobr 3 роки тому +6

    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 роки тому +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.

  • @asm-ex1jw
    @asm-ex1jw 8 років тому +1

    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

  • @edgar5686
    @edgar5686 5 років тому +1

    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

  • @vunguyenhoang3075
    @vunguyenhoang3075 5 років тому +1

    i think "push" variable can be rename to "resistance'

  • @douglasyamasaki1095
    @douglasyamasaki1095 5 років тому +1

    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.

  • @tushankhan1853
    @tushankhan1853 3 роки тому +1

    How to fix redefinition in collider??

  • @lva98
    @lva98 7 років тому

    Nice job, thanks!

  • @EricZeBaws
    @EricZeBaws 8 років тому +2

    Does it have to be a perfect square or would a rectangle work

    • @HilzeVonck
      @HilzeVonck  8 років тому

      +EricZeBaws The collider does not have to be a perfect square.

    • @EricZeBaws
      @EricZeBaws 8 років тому

      okay

  • @koraykahraman9031
    @koraykahraman9031 2 роки тому

    Please keep the tutorial videos coming

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

  • @Esteban3999
    @Esteban3999 7 років тому +4

    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 7 років тому

      same

    • @lukalazic7999
      @lukalazic7999 6 років тому

      Hey did you fix this problem?

    • @mr.lowpoly3882
      @mr.lowpoly3882 6 років тому +1

      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

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

  • @ron0gamingplayz102
    @ron0gamingplayz102 5 років тому +1

    8:29 Hilze is now an evil eyed sorcerer

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

  • @thebeanz7838
    @thebeanz7838 8 років тому

    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

  • @КристианИлиев-х5щ
    @КристианИлиев-х5щ 8 років тому

    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

  • @PleaseWait...
    @PleaseWait... 3 роки тому

    whats the point of (1.0f - push) ????

  • @shiwanggupta8608
    @shiwanggupta8608 6 років тому +1

    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

  • @RedubbledD
    @RedubbledD 7 років тому

    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?

  • @maxtwist3598
    @maxtwist3598 7 років тому

    it doesnt works if object are moving fast?

  • @AndrewOBannon
    @AndrewOBannon 8 років тому +1

    thanks

  • @parthrupareliya625
    @parthrupareliya625 5 років тому +1

    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 років тому +2

      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 Рік тому

      @@HilzeVonck I haven't quite figured out how to store the Collider inside of a variable, could you explain what you mean please?

  • @Lyoshiiro
    @Lyoshiiro 7 років тому

    is it possible to use this format/lib file to make 3D AABB instead of 2D AABB? * still for opengl

  • @dreamhollow
    @dreamhollow Рік тому

    I like this, but it's a lot more difficult to get to work with smart pointers.

  • @AdrianWitzil
    @AdrianWitzil 6 років тому

    I did it!!!

  • @EricZeBaws
    @EricZeBaws 8 років тому

    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  8 років тому

      +EricZeBaws do you mean the border of the screen?

    • @EricZeBaws
      @EricZeBaws 8 років тому

      Yes

    • @HilzeVonck
      @HilzeVonck  8 років тому +3

      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 8 років тому +1

      Thanks so much!!

  • @elijahandrushenko6313
    @elijahandrushenko6313 8 років тому

    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  8 років тому +1

      +Elijah Andrushenko Yeah, that is going to be the topic of the next video. :)

    • @lorow2542
      @lorow2542 8 років тому

      When we should expect it? :D

    • @HilzeVonck
      @HilzeVonck  8 років тому +4

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

  • @anonymousgaming911
    @anonymousgaming911 5 років тому

    Delta is called Δ in Greek Its the letter D

  • @fanut3599
    @fanut3599 6 років тому +1

    error: no matching function for call to 'Collider::CheckCollision(Collider, float)'
    anybody else had this problem? :(

  • @ThePlayerNotJump1
    @ThePlayerNotJump1 7 років тому +1

    You do know that, SFML has functionality to detect collisions right?

  • @johnmaquis6272
    @johnmaquis6272 6 років тому

    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?

  • @navaneeth6157
    @navaneeth6157 6 років тому +1

    holy shit this is soo hard :)

  • @fahdv2597
    @fahdv2597 6 років тому

    Bro how did you color code visual studio?

    • @ModerateDev
      @ModerateDev 6 років тому

      there's a bunch of tuts on YT

  • @stfoggy124
    @stfoggy124 2 роки тому

    at higher speeds you can easily glitch through the collision, does anyone know how to fix this?

  • @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 роки тому +2

      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

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

  • @thewhiteprogrammer9633
    @thewhiteprogrammer9633 2 роки тому

    Collsion GetCollider() { return Collsion(shape); there is a error coming collsion.h is not inaccesbile

  • @HiagoRAD
    @HiagoRAD 6 років тому

    My getCollider function is not working! It has no match for Collider(body). Does anyone had the same issue?

  • @johnlight-knight8060
    @johnlight-knight8060 4 роки тому

    I didn't understand the init-list (body(body)) but I will try to understand. :D

    • @boenaman4154
      @boenaman4154 4 роки тому +1

      What this means is that the private variable body, will be initialized by the parameter body which is given by the constructor.

  • @KKr0lik
    @KKr0lik 7 років тому

    I walk by the square, and its not moving. 0 errors or warnigs. whats wrong?

    • @traveler2158
      @traveler2158 7 років тому +1

      Maybe you should check if you are passing the body in the Collider class by a reference.

  • @sc5shout
    @sc5shout 7 років тому

    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.

  • @TheDorkol5
    @TheDorkol5 3 роки тому

    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  3 роки тому

      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 3 роки тому

      @@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 UA-cam video about aabb resolution.

    • @Herovy070
      @Herovy070 3 роки тому

      @
      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 3 роки тому

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

  • @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 років тому +1

      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 років тому +1

      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.

  • @christiancarter255
    @christiancarter255 2 роки тому

    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 2 роки тому

      I figured it out.

    • @mr.fantasy1
      @mr.fantasy1 9 місяців тому

      how
      @@christiancarter255

    • @woff5
      @woff5 5 місяців тому

      @@christiancarter255 what was wrong plz tell us

    • @christiancarter255
      @christiancarter255 5 місяців тому

      @@woff5 I wish I remembered 😔😭

    • @woff5
      @woff5 5 місяців тому

      @@christiancarter255 no worries someone had the same problem and had the awnser

  • @tundrummax6221
    @tundrummax6221 6 років тому

    will this only ever work for squares? will it ever work for rectangles?

    • @tundrummax6221
      @tundrummax6221 6 років тому +1

      Nevermind, I can see that it works.

  • @bondjovi4595
    @bondjovi4595 Рік тому

    Redraw
    Relocate

  • @Donaldbeebi
    @Donaldbeebi 4 роки тому

    this guy reminds me of pewdiepie lmao

  • @ahoiioha
    @ahoiioha 7 років тому +1

    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.

  • @richardlighthouse5328
    @richardlighthouse5328 7 років тому

    Please I need missing Clip!!!!!!!!!!!!!!!!!!!!!!

  • @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 5 місяців тому

      yeah same did you figure it out