Building a Simple 3D Scene with Physics in JavaScript & Three.js

Sdílet
Vložit
  • čas přidán 22. 02. 2022
  • Quick and easy setup of a JavaScript 3d Physics Engine in three.js and ammo.js.
    Support me on:
    Patreon: / simondevyt
    Follow me on:
    Twitter: / iced_coffee_dev
    Instagram: / beer_and_code
    Github: github.com/simondevyoutube/
    In this project I'll show you how to use ammo.js and three.js to setup a simple 3d scene with phyics in just a few minutes. We'll step through the basics of how to instantiate your physics world, and what the various options are, which can server to add a whole new dimension of possibilities to your 3D scenes.
    What we'll cover:
    * Three.js and Ammo.js initialization, how to instantiate your 3d physics world
    * Creating rigid bodies and simple shapes such as boxes and spheres
    * Using MotionState to synchronize transforms between the physics world and 3d scene.
    There's a lot of options for JavaScript 3d engines, like Ammo.js, oimo.js. cannon.js, etc. They're all extremely capable physics engines, but we'll be focusing on one in particular, ammo.js which is a wrapper around the Bullet physics engine.
    Full source code for the project is available, so if you're interested in fiddling with the code, screwing around with it, or improving it.
  • Věda a technologie

Komentáře • 81

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

    If you enjyoed this, check out my GLSL course: simondev.teachable.com/p/glsl-shaders-from-scratch
    Or support me on patreon!: www.patreon.com/simondevyt

  • @SuboptimalEng
    @SuboptimalEng Před 2 lety +20

    I just started a project with Three.js physics today - this could not have popped up on my recommendations at a better time. Thanks Simon!

  • @YippeePlopFork
    @YippeePlopFork Před 6 měsíci +1

    Newcomer to Three.js here. Very cool to see you building the solar system this way! Thank you for sharing this

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

    You're content is exceptionally entertaining and educating ... Thanks Simon. I am looking forward for your next video.

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

    Another great video after a long time. I missed these 👍

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

    Glad to see you back!

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

    I love your tutorials, it has such good content quality, it's unbelievable it's for free... I thank you for the entire community of developers that like me are being inspired by you! please never stop this I'll to spread the word about this channel!

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

    We need a interactive adventure game where you are the narrative voice.. guiding us to victory!!

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

    Very neat Simon!

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

    Just when I thought he was gone for good, he comes back with something I was looking for!!!!

  • @koki10190
    @koki10190 Před rokem +1

    this video helped me add Bullet Physics to my C++ Game Engine project
    Thank you for this video

  •  Před 2 lety +2

    Glad to have you back, Simon. 😊

  • @panmateusz
    @panmateusz Před 2 lety +14

    That would be super cool if you could do a video explaining web assembly.

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

    great explanation bro, love the vid

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

    That rocks! Love it

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

    i love your videos so much thank you

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

    I've used ammojs in a project a while ago, not remember precisely what made it really hard to setup (guess the integration with webassembly), but now I use cannon.js and let me tell you it works like a charm and it's really easy to setup and work with. Anyways, thanks for all these great videos!

    • @simondev758
      @simondev758  Před 2 lety

      I haven't tried it, but it looks great. For a while it was unmaintained, which was a negative but it looks like it's been picked up again. I'll try it out :)

    • @D3NM0NT3UR
      @D3NM0NT3UR Před 2 lety

      @Manuel, aside from the easy-to-use; which one has more stability and bdtrer performance? I'm genuinely curious

    • @manuelgamez8074
      @manuelgamez8074 Před 2 lety

      @@D3NM0NT3UR Sincerely I have no opinion rather than the developer experience I had. Maybe ammojs is more performant cause the integration with webassembly (but that is just an assumption). If helpful, in a scene with cannonjs I had 300+ sphere collisions and worked just fine.

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

    "Code will always make things clear." XD

  • @tomm.4447
    @tomm.4447 Před 2 lety +3

    MY BOY BE POSTIN AGAIN
    Missed your content man, great to see you uploading more stuff

    • @simondev758
      @simondev758  Před 2 lety

      Trying :) Life/pandemic has been really getting in the way.

    • @tomm.4447
      @tomm.4447 Před 2 lety +1

      Also, I think I requested an Ammo.js tutorial amongst others. Really glad you're so open about suggestions and requests

    • @simondev758
      @simondev758  Před 2 lety

      @@tomm.4447 Always open to suggestions, can't guarantee I'll do them but every suggestion goes on my list :)

  • @shujaa
    @shujaa Před 2 lety +6

    This tutorials are golden😍 I wonder how great it would be to see a legend like you recreating some simple games made in other game engines with three.js like subway surfers or creating a course I would buy one without a second thought.

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

      or a tutorial on reusable game components or design patterns for game programming in JavaScript.

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

      ooh man you literally blow my mind every time do you have a discord channel or smthn?

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

      These are great ideas, wrote them down. Nah no discord, have a twitter account if you wanna reach me there

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

    Wake up, SimonDev posted!

  • @kephas-media
    @kephas-media Před 2 lety +1

    He's back gents lolololol, let's go!!!!

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

    when tmpTransform_ appeared in the step_ function I could no longer follow, but I like to see you do physics now. Maybe there will be a RigidBody Component someday :)

  • @user-hd3pz2ow1b
    @user-hd3pz2ow1b Před 3 měsíci +1

    nice

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

    You put an underscore at the _end_ of your private member names!? ARE YOU OUT OF YOUR MIND!!? lol
    You mad lad, you. I approve. 👍

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

    Nice! I have used cannon but not ammo.

  • @MarvinDrude
    @MarvinDrude Před rokem +2

    Can you make a small tutorial where u create a networked version of this with client side prediction and stuff?

  • @pavelschannel-alittleoutof3532

    At last, clean code. Most of the links I have found just throw the code together in a most messy and disorganised manner and I hope for the sake of humanity that these people are never accepted as true developers or programmers. Thank you.

  • @kanpekiken2481
    @kanpekiken2481 Před rokem +1

    Hi Simon, picked a random video but my game is finally coming along using all the skills I’ve learned from your videos. Was wondering if you’d be interested in seeing it :)

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

    ammo.js seems good

  • @elnur0047
    @elnur0047 Před 2 lety +9

    I am big fan of your work sir, what do you think about creating RTS game with a WebRTC p2p lock-step networking? I believe it's one of the hardest genre to make it work on a browser, so it might provide a very interesting content, I wanted to create it myself but no idea where and how to start as a Threejs game dev guides are very limited to say the least. would appreciate some tips as well.

  • @orionnft5960
    @orionnft5960 Před 2 lety

    Hello simon!!! When I'm trying to deploy my repository github with netlify I have code:2 doesn't matter what kind of project... can you make a video one day about deploy the web... your job is awesome and very easy understand!! 👏🙌

  • @lycan2494
    @lycan2494 Před 2 lety

    What are the requirements/recommendations to actually follow this project video

  • @ColinRichardson
    @ColinRichardson Před 10 měsíci

    I am planning on doing rocks and sand... would this library be a good place to start? the rocks it seems like it would be good, but sand? soil? mud?

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

    Can you make a three.js cave generation tutorial ? I am looking for it for a long time but i can't make it.

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

      Maybe try looking up Marching Cubes. There is a great video from Sebastian Lague which explains it greatly.

    • @hey476
      @hey476 Před 2 lety

      @@manuelgamez8074 Actually i did found this video but i don't understand 😂

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

    How is the idea of using Svelte for reactivity and less codeing lines?

    • @simondev758
      @simondev758  Před 2 lety

      Could be interesting

    • @manuelgamez8074
      @manuelgamez8074 Před 2 lety

      Do you mean svelte for UI or for 3D development with three js? Personally I use svelte without even doubting when I have to include small UI components to my threejs apps because they works great with OOP structures and has lightweight bundle sizes. For the 3D, there is a project called svelthree which is like react three fiber but with svelte. Haven't checked it out yet but seems great if you are into functional programming (not my case but still interesting)
      Hope I answered!

    • @mdsalahuddin2841
      @mdsalahuddin2841 Před 2 lety

      @@manuelgamez8074 I meant for 3D development using library like three.js with Svelte

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

    Could you please try and move some of your game examples to React Native for Windows?

    • @simondev758
      @simondev758  Před 2 lety

      Yep those are on my list and I'm trying to get to that :)

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

    Use react-three-fiber

  • @dizzybeepot9856
    @dizzybeepot9856 Před rokem +1

    Would you be willling to upload the code for this 🥺.

  • @arturniko4293
    @arturniko4293 Před rokem

    where does this.tmpTransform_ come from at 6:20 ?

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

    How can i add gltf model as a rigid body?

  • @kalutstyle2256
    @kalutstyle2256 Před 2 lety

    Why do you prefer ThreeJS than BabylonJS ?

    • @simondev758
      @simondev758  Před 2 lety

      I don't, just haven't tried BabylonJS. It's eternally on my TODO list.

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

    Anticlimactic boxes that don't fall down to the ground are the worst.

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

    make a game,plz

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

    Bro you are getting old. 😀 👍

  • @31redorange08
    @31redorange08 Před 2 lety

    Something's broken in your set-up. Your fields end in an underscore.

  • @0GRANATE0
    @0GRANATE0 Před rokem

    Is Ammo.js better in performance than Cannon.js or Rapier.js? @SimonDev your 12cents on this?

    • @simondev758
      @simondev758  Před rokem

      No idea, haven't tested. Pretty sure ammo.js is emscripten of the C++ version, whereas cannon is pure JS? No idea about rapier, if I had to guess between the 3, based on this and nothing else, I'd guess that ammo is the most performant.