2D PHYSICS! // Game Engine series

Sdílet
Vložit
  • čas přidán 15. 09. 2021
  • Patreon ► / thecherno
    Live Stream ► / thecherno
    Instagram ► / thecherno
    Twitter ► / thecherno
    Discord ► / discord
    Code ► github.com/TheCherno/Hazel
    Series Playlist ► thecherno.com/engine
    #Hazel

Komentáře • 102

  • @TheCherno
    @TheCherno  Před 2 lety +71

    Hope you guys enjoy this absolute _banger_ of an episode! ❤️

    • @nexovec
      @nexovec Před 2 lety +2

      thank you, Cherno!

    • @zxuiji
      @zxuiji Před 2 lety

      Thought I'd mention something that popped into my mind while watching, a while ago I watched a vid where it mentioned 2d collisions are usually handled by square root because of the fixed z position but not on 3d collisions because of too many calls, I say bull on that, here's how I would do it with just 2 sqrt() calls:
      1. Get difference between x,y & z positions of both objects - for example o.x - p.x or p.x - o.x
      2. Square root with y & z and then y & x
      3. Divide the results by z and x, do not use y here
      4. We now have normalised square roots between 0 and 2, multiply them together
      5. If the final value is more than or equal to 1.0 a collision occurred, obviously no collision occurred if below 1
      **Edit:** maybe the reverse on that last statement, haven't expanded my code to physics yet since I'm struggling to fix depth handling of my *.png code (plan to take total control over memory management so I can dump Lua in as the scripting environment since it's so popular)

    • @nexovec
      @nexovec Před 2 lety

      @@zxuiji too expensive.

    • @zxuiji
      @zxuiji Před 2 lety

      @@nexovec Depends on how many objects your try to detect collisions with, for example if you know the main direction you're going is down then you can skip most of the objects around by simply checking if the normalisation of both x & z axis vs difference between the p.x/p.z and o.x/o.z is below 0.5, then you only have to check a few plus the objects directly below in same distance

    • @vb92614
      @vb92614 Před 2 lety

      What would it matter, subscriber interaction is virtually non existent in this channels comments. :P

  • @THExRISER
    @THExRISER Před 2 lety +81

    I currently don't need physics in any of my projects but if I ever need to implement Box2D I know there's a great video waiting for me, thanks for making this Cherno!

    • @irishbruse
      @irishbruse Před 2 lety +1

      What in the world are you making that doesnt need box2D it isnt just used for physics its most used for collision handling too

    • @THExRISER
      @THExRISER Před 2 lety +3

      @@irishbruse There are many games out there that don't have physics nor collision, but I'll answer your question.
      my first game was literally just a shoot 'em up and the framework I was using allowed for pixel perfect collisions (not part of the library but someone wrote a function for it) so I just used that because the only kind of collision I needed is one where both objects that collided would get deleted.
      My second project was a bit more complex but when I failed to setup Box2D with the framework I was using I just used the previous function to detect collision and then some simple algorithm that moves the object to it's previous position upon detecting collision to simulate solid objects.
      It wasn't perfect but got the job done.
      My current projects are a cellular-automata based game that has no collision, and some application that isn't a game.
      Hope that answers your question.

    • @THExRISER
      @THExRISER Před 2 lety +1

      @@stickguy9109 I mean, the very point of this series is to build your own engine as a learning experience.
      I'm using a framework to handle graphics since I'm not read to learn that yet, but, you know...
      So yeah to answer your question, I make games to better learn C++, and an engine is not the best tool for that since it does most of the work for you.

    • @THExRISER
      @THExRISER Před 2 lety +1

      @@stickguy9109 I am planning on starting gamedev for real so I'll be switching to an engine soon enough.
      Good luck with C++, it can be a pain in the ass at the start.

    • @THExRISER
      @THExRISER Před 2 lety +1

      @@stickguy9109

  • @mastershooter64
    @mastershooter64 Před 2 lety +57

    me who wrote my own 2D physics engine: _cries in shitty buggy physics engine that I didn't even finish_ also _smiles in having had fun while making it and having learned a lot while making it_

    • @KevinDay
      @KevinDay Před 2 lety +2

      Those sound like happy tears 😊

    • @mastershooter64
      @mastershooter64 Před 2 lety +1

      @@KevinDay haha it's both happy and sad, but more so happy than sad

    • @gracicot42
      @gracicot42 Před 2 lety +1

      I am also guilty of this

    • @Drillgon
      @Drillgon Před 2 lety +1

      Same for me, but 3d. That thing was a mess, didn't even have features like constraints or IK, destabilized often, and wasn't very fast, but dang, it felt great to learn how to do it myself, and it worked pretty well for the small project I was doing at the time. I'm ultimately glad I didn't go with a library.

    • @mastershooter64
      @mastershooter64 Před 2 lety +1

      @@Drillgon That's the next thing I'm gonna do lol a 3D physics engine, a after that an nD physics engine right after I write a geometric algebra library

  • @thetruedjlivewire
    @thetruedjlivewire Před 2 lety +2

    honestly the troubleshooting is what makes watching these videos so much better then watching someone who doesn't explain debugging or error fixing.

  • @gracicot42
    @gracicot42 Před 2 lety +13

    At 28:03, you can use unique pointer with incomplete types very well. However the destructor of your class must be defined in a place where it is complete, so doing `~Scene() = default` won't work, you have to define your destructor in the cpp file, as you already do. It took me a while to understand that.

  • @nhanNguyen-wo8fy
    @nhanNguyen-wo8fy Před 7 dny

    19:05 static body
    20:10 collider
    29:30 gravity
    31:10 create body

  • @movingheadmau8128
    @movingheadmau8128 Před 2 lety +1

    Really enjoying the "redone" coding sessions and the way you explain the code you write line by line.

  • @Convolva
    @Convolva Před 2 lety +4

    Congrats on 400k subs! You deserve it! ❤️

  • @akriminsoe5527
    @akriminsoe5527 Před 2 lety

    You are the best developer. I never seen like you before. You did make your own graphics and physics engine. congratulations bro!

  • @samochreno
    @samochreno Před 2 lety

    Thank you so much, this helped me implement Box2D so easily, this is the best resource on implementing it I could find

  • @rob-890
    @rob-890 Před 2 lety +5

    Guy in Australia actually got arrested for interacting with a headerphile.

  • @QckSGaming
    @QckSGaming Před 2 lety +4

    Awesome video! Really helpful, even if a bit "rushed" (could use some extra explanation on the details or some tutorial walkthrough type of deal). :)
    Have you considered using ReSharper or similar tooling to generate boilerplate / switch-statements / use machine-learning to type stuff for you? Or do you maybe not like them and like to do things manually to "keep a hold of the reins" so to speak?

  • @lengors1674
    @lengors1674 Před 2 lety +8

    There's a bug in the UI for the box collider. The property size in the UI is binded to the offset of the component.

  • @lennihuopa
    @lennihuopa Před 2 lety +1

    So close to 400k!

  • @jackkensik7002
    @jackkensik7002 Před 2 lety

    another great video , keep it up!

  • @Destroyer19941995
    @Destroyer19941995 Před 2 lety

    OMG SO EXCITED FOR THIS. HERE WE GO!

  • @mind2654
    @mind2654 Před 2 lety +1

    I'm not very knowledgeable in C++ nor graphics/physics programming but these videos are bangers
    I love them
    Thanks!

  • @ujjwalraut6340
    @ujjwalraut6340 Před 2 lety

    Damn was expecting this tomorrow

  • @dingoDogMan
    @dingoDogMan Před 2 lety +1

    I see my mans been getting himself into some chess!

  • @devdutmn9608
    @devdutmn9608 Před 2 lety

    Whoa this is amazing

  • @arin_faraj
    @arin_faraj Před 2 lety

    Awesome stuff

  • @siddharthasarmah9266
    @siddharthasarmah9266 Před 2 lety

    code is actually a command. So for the application u need to type vscode. And if you are in a folder in command prompt. You can type code . To open the folder. A quick little tip

  • @sam_is_people1170
    @sam_is_people1170 Před 2 lety

    thanks!

  • @Light-wz6tq
    @Light-wz6tq Před 2 lety

    Noicee game engine episode

  • @guywithknife
    @guywithknife Před 2 lety

    Wait, does the error not tell you which files included the header? I use clang and when there's errors (any kind) in a header, it tells me all the includes from the source file to the error (eg "error in foo.h, included from bar.h included from main.cpp")

  • @pianochannel100
    @pianochannel100 Před 2 lety +1

    You know what, one of these days it might be nice to make people aware of the risks of carpal tunnel and techniques to avoid injuring yourself. If your hands are your living its very important to avoid injuring them. Im a concert pianist / software engineer with developing carpal tunnel :(

  • @RagdollRocket
    @RagdollRocket Před 2 lety

    love it!

  • @lithium
    @lithium Před 2 lety +1

    unique_ptr can absolutely be used for forward declarations, but you need to do the forward declaration outside the template.
    class b2World;
    std::unique_ptr m_World; // works
    std::unique_ptr m_World; // doesn't work
    There's also some specificity that depends on the destructors of the owning class not being inlined but yeah. Come to think of it for the sake of your video it's probably easier to just say you can't use them ;)
    A virtual ~Scene() = default; will be enough to allow std::default_delete to know enough to do the right thing.

  • @m.hosseinmahmoodi
    @m.hosseinmahmoodi Před 2 lety

    29:47 "Meters per second per second" or "meters per second square"

  • @aloluk
    @aloluk Před rokem

    You say about strings for enums, but is you projectionType still saved as an enum or a string?

  • @Anequit
    @Anequit Před 2 lety

    When visual studio starts getting slow clear it's cache. It's speeds up SO MUCH.

  • @jetweilee1645
    @jetweilee1645 Před 2 lety

    if there is any possible to create a time-line of your video on the description zone where below the video?
    it will be more efficient to watch (like just jump to the time which I'm interest in) ^^
    Sorry for my bad english :)

  • @devpartap9748
    @devpartap9748 Před 2 lety +1

    2D is Cool!

  • @slygamer01
    @slygamer01 Před 2 lety

    Why would a string cast include dual quaternion? String cast seems to pull in a _lot_ of stuff.

  • @matheus-kirchesch
    @matheus-kirchesch Před 2 lety

    is hazel now open to contribute? or still for patreons only?

  • @anusheeltiwari
    @anusheeltiwari Před 2 lety

    That H looks like a hostinger logo, not exactly the same but very close. Very very close.

  • @jerrya17
    @jerrya17 Před 2 lety +7

    2D or not 2D. That is the question!

  • @CacheTaFace
    @CacheTaFace Před 2 lety

    Alt title: Australian man teaches the web about forking

  • @MetinCloup
    @MetinCloup Před 2 lety +1

    can you make a tutorial for java about box2D?

  • @mrviva5507
    @mrviva5507 Před 2 lety

    hey, is there any way to download your syntax coloring or your settings??

  • @arsdever8957
    @arsdever8957 Před 2 lety

    4:41 how is this extension called?

  • @Destroyer19941995
    @Destroyer19941995 Před 2 lety

    Why is it not fixed timestep?

  • @max_ishere
    @max_ishere Před 2 lety

    RigidBodyToBox2D thing why not replace it with a cast overload?

    • @nullbeyondo
      @nullbeyondo Před rokem

      Because as he said, he likes being explicit with such things. And I honestly agree with him. They don't even have the same enum values and might be expanded later so it is confusing to mix them together.

  • @michaelvanrheede7225
    @michaelvanrheede7225 Před 2 lety

    Are you developing this engine by yourself?

  • @aloluk
    @aloluk Před rokem

    If you just added encode/decode to all your component types, then new types would be much easier to add serialisation for.

  • @Mempler
    @Mempler Před 2 lety

    We've tried to implement box2d on our engine but miserably failed

  • @rob-890
    @rob-890 Před 2 lety +14

    Who's betting he's gonna pull in another library? I can understand doing it for physics but gizmos and the like come on!

    • @Chimponaut
      @Chimponaut Před 2 lety +5

      You can go a step beyond this and just use a game engine too!

    • @irishbruse
      @irishbruse Před 2 lety +13

      @@Chimponaut
      #include
      Thanks for watching everyone this is the end of the Hazel engine

    • @gommito
      @gommito Před 2 lety +2

      @@irishbruse From what i know Unity also uses Box2d for its 2d physics engine

    • @CoolModderJaydonX
      @CoolModderJaydonX Před 8 měsíci +1

      ​@@gommitoHuh. REALLY?

  • @ThylineTheGay
    @ThylineTheGay Před 2 lety

    Oh no, box 2d

  • @blacklistnr1
    @blacklistnr1 Před 2 lety

    why use a custom build solution? all the including and compiling with dependencies is CMake's job.

  • @danielhildebrand7684
    @danielhildebrand7684 Před 2 lety

    Hey!

  • @cupofdirtfordinner
    @cupofdirtfordinner Před 2 lety

    PLEASE add softbody support
    actually there might be softbody support, i havent watched the whole video yet, but if there isnt softbody support you should add it

  • @Jkauppa
    @Jkauppa Před 2 lety

    yes over an hour lol

    • @Jkauppa
      @Jkauppa Před 2 lety

      multithreading support for all components, no actual main logic loop, only delegate calls()

    • @Jkauppa
      @Jkauppa Před 2 lety

      if you have separate 32-bit RGBA lighting buffer per pixel, color + light, total 64-bit, then you have more dynamic range, not messing up the color below

    • @Jkauppa
      @Jkauppa Před 2 lety

      what is a transparent of a transparent light, or just white light, un-colored light, all colors, bloom light, so you have RGB+A+L-RGB+W

  • @marcceulemans6842
    @marcceulemans6842 Před 2 lety

    I wander? Would it be practical to dump a "clean project with include - lib and project - solution" in Dropbox ant would inporting it in an empty dev folder work as a valid startup solution for youself and any other aspiring coders out here?

    • @holybubbles
      @holybubbles Před 2 lety

      For most languages, no, that wouldn't be a good solution. The problem C++ has is there are no standard package managers so generally I think most people just download libraries and set them up on a project by project basis. If there's a library you use very often like boost, I think it'd make sense to just keep it saved on your system somewhere. Other than that, setting up any specific library configuration would only take about 10 minutes or so, especially when that library utilizes CMake

  • @nexovec
    @nexovec Před 2 lety +4

    I like to collide my own polygons, so I'm gonna pass on Box2D.

    • @K3dev
      @K3dev Před 2 lety

      Subscribed in case you decide to document it in videos

    • @Drillgon
      @Drillgon Před 2 lety

      This is the way.

    • @Drillgon
      @Drillgon Před 2 lety +1

      As a side note, Erin Catto (guy who made box2d) has some great presentations and papers on implementing physics.

  • @local.interloper
    @local.interloper Před 2 lety +1

    hi

  • @oamioxmocliox8082
    @oamioxmocliox8082 Před 2 lety

    ;)

  • @kashnigahbaruda
    @kashnigahbaruda Před 2 lety

    You should sort alphabetically. Always.

  • @syirogane
    @syirogane Před rokem

    Neat trick, but it's really nice when the compiler (here, gcc, but clang does similar) does it for you:
    In file included from ../include/QF/progs.h:37,
    from ../nq/include/sv_progs.h:35,
    from ../nq/include/server.h:41,
    from ../nq/source/sv_ded.c:43:
    As for ensuring code compiles before committing: that's a little much (probably doable), but before pushing has saved me a lot of pain, just use a pre-push hook:
    $ cat .git/hooks/pre-push
    #! /bin/sh
    cd ~/src/qf/quakeforge/o.o
    make -j