Rigidbody in Unity - Everything You Need to Know

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 130

  • @Rat-k3f
    @Rat-k3f 7 วันที่ผ่านมา +1

    One of the most informative tutorial that I've ever seen in a while.
    I love how you pay attention to explain how each elements works with given example.

    • @anandev
      @anandev  7 วันที่ผ่านมา

      Wow thank you... This means a lot to me

  • @thanhnguyenchi7413
    @thanhnguyenchi7413 ปีที่แล้ว +12

    The final quote on how we are not breaking physics laws but altering the nature of it to our needs is brilliant

    • @anandev
      @anandev  ปีที่แล้ว +3

      Yessss! Thank you so much for the compliment! i'm glad that writing scripts beforehand proved to be useful! 🤓 Ty once again

  • @EngerJimenez
    @EngerJimenez 12 วันที่ผ่านมา +1

    Quite late but consider making a full playlist of this.
    Loved the examples in-game. :)

    • @anandev
      @anandev  12 วันที่ผ่านมา

      Of course! What sort of videos would you like on this playlist? Should it be about different components in Unity or should it be about things within the Rigidbody component?

  • @aldigangster123
    @aldigangster123 4 หลายเดือนก่อน +6

    This is one of the best videos on rigidbody I've seen! Well done!

    • @anandev
      @anandev  4 หลายเดือนก่อน

      Thank you so much!! This means a lot! 🥹♥️

  • @GatorGuyGame
    @GatorGuyGame 2 ปีที่แล้ว +5

    explanation between Mass and Drag in relation to freefall was very helpful; thanks for this vid!

    • @anandev
      @anandev  2 ปีที่แล้ว +1

      Woah! 🤩 I'm glad it was helpful!

    • @GatorGuyGame
      @GatorGuyGame 2 ปีที่แล้ว

      @@anandev Very helpful; trying to figure out a nice combat system/character controller using rigidbody over here!

  • @Corb4l
    @Corb4l ปีที่แล้ว +4

    Your video edit is spot on, the visual examples make everything quite easy to understand. Great job, many thanks :)

    • @anandev
      @anandev  ปีที่แล้ว +1

      I'm glad that the 2 months of editing (which included 2 whole retakes) was totally worth it 😃 Happy that the video helped!

  • @canman918
    @canman918 2 ปีที่แล้ว +4

    This is mad underrated I learned a lot of stuff from this

    • @anandev
      @anandev  2 ปีที่แล้ว

      Woah! I'm happy that this was useful! I'm glad me spending time on it was worth it! Tysm! ❤

  • @deraminator945
    @deraminator945 ปีที่แล้ว +6

    I hope your channel grows fast because these are very well made videos :) very clean and easy to understand :)

    • @anandev
      @anandev  ปีที่แล้ว

      Aw! Thank you so much... It means a lot 🥰

  • @abhisheksuper20
    @abhisheksuper20 ปีที่แล้ว +3

    An ultimate tutorial indeed. this answered all questions i had regarding physics!!

    • @anandev
      @anandev  ปีที่แล้ว

      Thank you so much!! The purpose of this video is to just simply give you an idea of the fundamentals of the Rigidbody component. Using it for custom physics is a whole another game, and requires a lot of experimentation to make things close to perfect. But I'm glad this video gave you some insight on some things 😊

  • @creativeyes3292
    @creativeyes3292 2 ปีที่แล้ว +2

    Those drawings are really cute and as I have said before the production value is top

    • @anandev
      @anandev  2 ปีที่แล้ว

      Woahhh!! This video took a month to make, and I'm glad you feel that way 🥰

  • @sssquirrelyalt
    @sssquirrelyalt ปีที่แล้ว +1

    OMG thank you so much just the first part about the collisions helped me solve multiple problems I had!

    • @anandev
      @anandev  ปีที่แล้ว

      Yayy!! I'm glad it helped!

  • @SaimJuttGameDev
    @SaimJuttGameDev ปีที่แล้ว +1

    arguably the best explanation EVER!!!

    • @anandev
      @anandev  ปีที่แล้ว

      Thank you so much!! It means a lot 🥰

  • @kashyapp23
    @kashyapp23 10 หลายเดือนก่อน +2

    brother you put in so much useful info in so little time
    thank you

    • @anandev
      @anandev  10 หลายเดือนก่อน

      Awww! This made my evening! Thank you very much and I'm glad the video was useful! 😁

  • @bigedwerd
    @bigedwerd ปีที่แล้ว +1

    I watched a video about the physics behind Mario's jump that really helped me break away from the "must make it realistic" mindset. It's more important to make a game feel good.

    • @anandev
      @anandev  ปีที่แล้ว +1

      Yes I remember watching something like that. What helped me was the game Rocket League. I lovedd it when they break all laws of physics.

  • @DEEPAKSINGH-491
    @DEEPAKSINGH-491 2 ปีที่แล้ว +2

    Great Efforts and nicely explained

    • @anandev
      @anandev  2 ปีที่แล้ว

      Thanks a lot, and I'm glad you liked it

  • @T6her
    @T6her ปีที่แล้ว +1

    شكرا جدا على هذا الفيديو الرائع جدا أتمنى لك الافضل يا صديقي

    • @anandev
      @anandev  ปีที่แล้ว

      Thank you very much for the kind words! 😊

  • @honkhonk5000
    @honkhonk5000 9 หลายเดือนก่อน +1

    Great great great tutorial! I’m definitely going to reference this again.

    • @anandev
      @anandev  9 หลายเดือนก่อน

      Yaaayy! Glad the video was useful 🤗

  • @GaganKumar-fz6wz
    @GaganKumar-fz6wz 9 หลายเดือนก่อน +1

    Thank you so much for this great video. This video helps to solve my problems.

    • @anandev
      @anandev  9 หลายเดือนก่อน +1

      Thank you so much for taking your time to comment this 🤗♥️ I'm glad this was useful

  • @mrpro877
    @mrpro877 ปีที่แล้ว +1

    makes it all look easy... great tutorial

    • @anandev
      @anandev  ปีที่แล้ว

      Thank you! Cheers! I'm glad it helps!

  • @semi_jared39
    @semi_jared39 ปีที่แล้ว +1

    sheeesh, this channel is great. Explanations are pretty clear.

    • @anandev
      @anandev  ปีที่แล้ว

      Aww 🥰 I'm glad you think so. Thank you so much

  • @lln6123
    @lln6123 10 หลายเดือนก่อน +1

    This is so well explained!! Thanks alot

    • @anandev
      @anandev  10 หลายเดือนก่อน

      Thank you so much! I'm glad the video was useful 😃

  • @trevortakahashi3086
    @trevortakahashi3086 9 หลายเดือนก่อน +1

    Thank you, that was super informative i learned soo much

    • @anandev
      @anandev  9 หลายเดือนก่อน

      Thank you for taking your time to let me know 😭♥️ I'm glad the video was useful

  • @appstuff6565
    @appstuff6565 13 วันที่ผ่านมา +1

    What a beautiful tutorial. Thank you! Subbed,, Liked and Commented!

    • @anandev
      @anandev  13 วันที่ผ่านมา +1

      Thank you sooo much 🥹❤️ You made my day, this means a lot

    • @anandev
      @anandev  13 วันที่ผ่านมา +1

      Also I forgot, I'm glad the video was useful.

    • @appstuff6565
      @appstuff6565 9 วันที่ผ่านมา +1

      @@anandev indeed.

  • @TricoliciSerghei
    @TricoliciSerghei ปีที่แล้ว +1

    Very good video, thank you very much!

    • @anandev
      @anandev  ปีที่แล้ว

      Yay! I'm glad it was useful!

  • @khalidzouzal8417
    @khalidzouzal8417 7 หลายเดือนก่อน +1

    Thank you veryyy much, you're so good !

    • @anandev
      @anandev  7 หลายเดือนก่อน

      Yayy! I'm happy I could help! 🤗

  • @ryan_raus
    @ryan_raus 3 หลายเดือนก่อน +1

    Incredible video!!

    • @anandev
      @anandev  3 หลายเดือนก่อน

      Thank you so much! I'm glad the video is useful!

  • @dogebella
    @dogebella 11 หลายเดือนก่อน +1

    Very good video. Thank you 🙏

    • @anandev
      @anandev  11 หลายเดือนก่อน

      Thank you too!

  • @regys9521
    @regys9521 10 หลายเดือนก่อน +1

    Simple the best tips ever!

    • @anandev
      @anandev  10 หลายเดือนก่อน

      Thank you so much!! I'm glad you've found it useful

  • @holychild-tq7mm
    @holychild-tq7mm 7 หลายเดือนก่อน +1

    Thanks great video.

    • @anandev
      @anandev  7 หลายเดือนก่อน

      Thank you so much for watching. I'm glad it's useful 😃

  • @user-pn7wq9cl1g
    @user-pn7wq9cl1g 3 หลายเดือนก่อน +1

    I didn't know that rigidBody physics update at a fixed 50/s rate. Damn.

    • @anandev
      @anandev  3 หลายเดือนก่อน

      Yeah it's really useful to know that. I don't remember if I have mentioned it in the video, but we can change that in the project settings.

  • @halivudestevez2
    @halivudestevez2 6 หลายเดือนก่อน +1

    Rigidbody has a role in detecting collisions.... (OnCollisionEnter)

    • @anandev
      @anandev  6 หลายเดือนก่อน

      Yes! Collision and Trigger Events are only registered when one of the two bodies contain a Rigidbody! 😸

  • @4hSx
    @4hSx 11 หลายเดือนก่อน +1

    Really good video.

    • @anandev
      @anandev  11 หลายเดือนก่อน

      Thank you so much 😊

  • @sibasisrath6774
    @sibasisrath6774 8 หลายเดือนก่อน +1

    Love it.

    • @anandev
      @anandev  8 หลายเดือนก่อน +1

      Thank you so much 😊 Glad you love it!

  • @GuiJardim
    @GuiJardim ปีที่แล้ว +1

    great video!

    • @anandev
      @anandev  ปีที่แล้ว

      Thanks! I hope it was useful! 😊

  • @cemberber3326
    @cemberber3326 9 หลายเดือนก่อน +1

    You are King

    • @anandev
      @anandev  9 หลายเดือนก่อน

      We are all KINGS 👑

  • @halivudestevez2
    @halivudestevez2 6 หลายเดือนก่อน +1

    nice tutorial!

    • @anandev
      @anandev  6 หลายเดือนก่อน

      Thank you so much! I'm glad it is useful!

  • @cade5792
    @cade5792 ปีที่แล้ว +1

    Great video!

    • @anandev
      @anandev  ปีที่แล้ว

      Thanks! Glad you enjoyed it 😃

  • @ShatabdaRoy115
    @ShatabdaRoy115 2 ปีที่แล้ว +1

    Thanks mate

    • @anandev
      @anandev  2 ปีที่แล้ว +1

      I'm glad the video was helpful ☺

  • @abg2487
    @abg2487 2 ปีที่แล้ว +1

    Great 👍👍 make other video about to think logic of games and code it

    • @anandev
      @anandev  2 ปีที่แล้ว

      Thanks! 🥰 Do you have any specific game in mind?

    • @abg2487
      @abg2487 2 ปีที่แล้ว +1

      @@anandev ludo

    • @anandev
      @anandev  2 ปีที่แล้ว

      @@abg2487 On it! Sorry for the late reply! Didn't get the notification for some reason.

  • @phamduy2053
    @phamduy2053 20 วันที่ผ่านมา +1

    good video sir

    • @anandev
      @anandev  20 วันที่ผ่านมา

      Thanks! Glad the video was useful!

  • @aminullah5939
    @aminullah5939 2 ปีที่แล้ว +1

    sir great work please upload character movement script explain

    • @anandev
      @anandev  2 ปีที่แล้ว

      Thank you so much! If it's not too much trouble, can you tell me exact time stamp in this video for the character movement, so I can confirm your area of interest.
      I'm not sure if this is exactly what you're talking about, but I do have a video on 2D platformer character movement using the new input system, link below, so please check it out and let me know if this is it👇
      th-cam.com/video/rKqO_PEwBWA/w-d-xo.html
      Thanks again, and hope this helps!

  • @6clix331
    @6clix331 ปีที่แล้ว +1

    i have a question. isn't it better to multiply whatever phys calculations we have by Time.deltaTime in Update() rather than just putting it in FixedUpdate()? for example , in the case of player movement , it would lead to more responsive inputs because it updates every frame rather than a fixed amount of times per second

    • @anandev
      @anandev  ปีที่แล้ว

      Good question! No matter where you put your physics calculations, Unity executes its physics update only a fixed number of times per second. This synchronizes well with the FixedUpdate().
      Just to clarify, the calculations CAN be made in Update() but the actual motion of the body occurs along with the FixedUpdate() and it happens internally.
      But I would recommend writing code in FixedUpdate() only because of the fixed frame rate, and the calculations would not be off.
      Also, multiplying calculations by Time.deltaTime, only makes sense for equations that are dependent on time directly.
      For example, Displacement = Velocity * Time
      In a practical case, it would be:
      transform.position (Delta Displacement) = speed * direction.normalized (Velocity) * Time.deltaTime (Delta Time)
      Time.deltaTime is not needed when it comes to using functions like Rigidbody.AddForce()
      For better responsive Inputs, you can perform your Input inside Update() and cache your result in a variable and use conditions inside FixedUpdate() on these variables and perform the calculations there.
      NOTE: The only time where using Update() for physics calculations (in my opinion) is when there is NO ACCELERATION to the body. If we want to gradually increase the speed of the player, when it starts moving or something, it is better to use FixedUpdate(). At 7:50 in the video, the velocity is being set inside Update() only. This is because we are setting the velocity and not incrementing it.
      If it was rb.velocity "+=" instead of "=", then it would mean acceleration and then the physics would not be accurate. At Fixed Speeds, It doesn't matter where you update the velocity.
      I hope this comment was not too difficult for you to understand 😊

    • @6clix331
      @6clix331 ปีที่แล้ว

      @@anandev thanks! i didn't know physics worked like that in unity

  • @fokeyjo
    @fokeyjo 8 หลายเดือนก่อน +1

    Just a suggestion that you should lower the volume of the popping noises, they get distracting. Great content, though.

    • @anandev
      @anandev  8 หลายเดือนก่อน

      Thanks for the tip! Yes I agree, I believe I forgot to turn down the volume of the sfx track for that video 😅 But I'll make sure to not repeat it!
      By the way, I'm happy you liked my content!

  • @talismanskulls2857
    @talismanskulls2857 ปีที่แล้ว +1

    I get the concept but the one thing I am not seeing is how to actually use physics to walk up steps of different levels and not trying to put things in with invisible ramps all over the place that just wont work for many reasons. Every time i see any "examples" it is always someone putting rb.transform in physics or raycasts that dont work.
    For example from one "tutorial" you create a couple of game objects for slots and do something like this:
    RaycastHit hitLower;
    if (Physics.Raycast(Feet.transform.position, transform.TransformDirection(1.5f, 0, 1), out hitLower, 0.1f))
    {
    rb.position += new Vector3(0f, stepHeight * thrust * Time.deltaTime, 0f);
    RaycastHit hitUpper;
    if (!Physics.Raycast(Knees.transform.position, transform.TransformDirection(-1.5f, 0, 1), out hitUpper, 0.2f))
    {
    rb.position -= new Vector3(0f, -stepSmooth * Time.deltaTime, 0f);
    }
    }
    It doesn't actually work and i have tried changing the numbers and editting this or that, replacing the numbrs with Vector 3,forward, and so on. Its garbage. No one else seems to have a straight out simple or specific code to do that. Also i am not using transforms with jumpig but can't get the jumping animation in the editor to work with the script. It will jump but wont add the animation and again that is following all the various "tutorials" precisely or going to the unity docs. Its a problem in all versions of the engine.

    • @anandev
      @anandev  ปีที่แล้ว +2

      Stairs are a bit of a hiccup when it comes to video games. Its going to be hectic to use physics for that in my opinion. Better alternatives may include faking it (using invisible ramps) and using particle effects at the feet (mostly used in 2d games to hide the feet while climbing). The invisible ramps are great for first person games but you need to fine tune it for other types of games.
      If you need realistic results, you'd probably have to go for procedural animations and procedural IK movement and stuff and not use manual physics, and I don't think there are tutorials out there for that. You may have to use manual logic and code things, or buy an asset pack, perhaps?
      If you could get away with ramps, DO IT! Most Indie games do it.
      If I were to code it with Physics, I would first check if the player is grounded (using raycast). If it is grounded, check if it is hitting a wall from its feet (forward raycast) and simultaneously check if the wall ahead is actually a large wall or a step on stair, by creating a float maximumStepHeight variable and then check if it is hitting the same wall (forward raycast). Make sure that all these raycasts have a small distance of "0.1f" or something and is not set to infinity (which is by default). If the stepHeight raycast hits the same wall, then it means the wall in front is too big for the player to climb. If the stepHeight raycast doesn't hit anything, it means that there is a wall detected by the feet raycast, but there is no wall detected by the stepHeight raycast, which means that the wall ahead is actually a step of the stairs. Now you can either lerp the position or change it directly if you wish.
      Also, For your code, trying debugging the rays, make sure that the rays are in the proper direction and is actually hitting something. Following any "tutorial" blankly will almost never work and please don't expect tutorials to be that perfect. There would definitely be hidden reasons that are affecting your simulation that are different from the tutorial.
      Also with your doubts with the animation not working, there could be a lot of reasons why it may not be working. The context provided is not enough to figure out a solution.
      Hope this helps 😊

  • @foncode101
    @foncode101 9 หลายเดือนก่อน +1

    Subscribe , very good my friend! Loved it!

    • @anandev
      @anandev  9 หลายเดือนก่อน +1

      Thank you so much! It means a lot ♥️

  • @Markizon4ik
    @Markizon4ik 8 หลายเดือนก่อน +1

    Why does the velocity in the rigidbody component have coordinates?

    • @anandev
      @anandev  8 หลายเดือนก่อน +2

      Velocity (Anything that requires a direction) is a vector3 and position (Coordinates) is also a vector3.
      Let me put it this way:
      A position needs an x,y, and z right? Therefore they are stored in a Vector3 variable.
      A direction from positionA to positionB is the difference between two vectors, or (B - A)
      But a position P can also be used like a vector, because it is essentially the direction to that point on the world, from the world origin or (0,0,0), or in mathematical terms P = (P - 0)
      There is a root Game object for all Gameobjects in Unity that we can't see called "Viewport" and anything that is a child of this Viewport is something that exists.
      Basically in physics, a vector has a magnitude and a direction. When making a game engine, it is important to have an origin and to know the relative positions of Game Objects from one another so that we can make a world out of it.
      Therefore we can essentially use the position of the game object like a vector because fundamentally it is a direction from the origin.
      In the case of velocity, it is displacement over time, and displacement needs a direction and hence a Vector3 is used.
      Essentially, we use Vectors to represent directions, but it just so happened to be that in game engines, positions happens to be a direction as well.
      I hope this was useful ☺️ and I hope this all makes sense.

    • @Markizon4ik
      @Markizon4ik 8 หลายเดือนก่อน +1

      @@anandev Thank you!

    • @anandev
      @anandev  8 หลายเดือนก่อน

      You're welcome 🤗

  • @klaus117gaming
    @klaus117gaming ปีที่แล้ว +1

    I cant seem to find the info panel in my unity editor. HELP!!!

    • @anandev
      @anandev  ปีที่แล้ว +1

      There is this window called Physics Debugger, the info panel moved over there in the later versions of Unity 2022

    • @klaus117gaming
      @klaus117gaming ปีที่แล้ว +1

      Oh Thank you! 👌🏽

    • @anandev
      @anandev  ปีที่แล้ว

      You're welcome! 😊

  • @animalfun7794
    @animalfun7794 ปีที่แล้ว +1

    😍

    • @anandev
      @anandev  ปีที่แล้ว

      Thank you! 🥰

  • @ItzCramer
    @ItzCramer 4 หลายเดือนก่อน +1

    man i love Indians, thanks man :)

    • @anandev
      @anandev  4 หลายเดือนก่อน

      Haha! It's my pleasure 😁

  • @clarkkent1473
    @clarkkent1473 10 หลายเดือนก่อน +1

    That tongue roll tho

    • @anandev
      @anandev  10 หลายเดือนก่อน

      Yes it's my signature rizz move 🤭😎

  • @carlosjaviersilva4751
    @carlosjaviersilva4751 7 หลายเดือนก่อน +1

    you saved my life
    and my wife

    • @anandev
      @anandev  7 หลายเดือนก่อน

      Well, I guess I can add "life saver" to my resume now!

  • @anilbabu9075
    @anilbabu9075 2 ปีที่แล้ว +1

    🤩😍

    • @anandev
      @anandev  2 ปีที่แล้ว

      Thank you 😇❤

  • @maikonjipa
    @maikonjipa ปีที่แล้ว

    RigidBody ou Character Controller para movimento de players

    • @anandev
      @anandev  ปีที่แล้ว

      Use Rigidbody for most games (If you want to use OnCollision or Trigger Events, or use Physics, which most games may have).
      Go for Character Controller if your gameplay is simple, and doesn't involve too many collisions and fast movement.
      CharacterController is way faster, but it lacks full control and may be iritating. Go for it, if your game is a first person horror game, or an experience or something like that which doesn't involve too much accuracy when it comes to simulating physics.

  • @uhohwhy
    @uhohwhy 10 หลายเดือนก่อน +3

    hallo your computer has virus

    • @anandev
      @anandev  10 หลายเดือนก่อน

      My computer also has anti-virus

    • @uhohwhy
      @uhohwhy 10 หลายเดือนก่อน

      @@anandev copege

    • @anandev
      @anandev  10 หลายเดือนก่อน

      @@uhohwhy haha sorry

  • @tbtmtfth
    @tbtmtfth 8 หลายเดือนก่อน +1

    bro "Anan" means "Your Mother" in Turkish 💀💀

    • @anandev
      @anandev  8 หลายเดือนก่อน +1

      Hahaha, Didn't know that🤣🤣 My name is Anand by the way, which means 'Happiness', But you can call me Anan, because it feels funny now 😂

    • @tbtmtfth
      @tbtmtfth 8 หลายเดือนก่อน +1

      @@anandev 😄 Nice video btw thanks

    • @anandev
      @anandev  7 หลายเดือนก่อน +1

      Thank you so much! Me glad the video is useful! 😸

  • @bombrman1994
    @bombrman1994 7 หลายเดือนก่อน +1

    too much sound effects and pops i cant watch

    • @anandev
      @anandev  7 หลายเดือนก่อน

      Yeah it was an honest mistake! I'll make sure to not repeat it ☺️

  • @jean-loupmartin6067
    @jean-loupmartin6067 2 ปีที่แล้ว

    Excellent video ! I've learned a lot in a short time, thx ! :)
    5:16 Rigidbody rb => GetComponent(); Isn't better to cache it ?

    • @anandev
      @anandev  2 ปีที่แล้ว +1

      Yay! I'm glad the video was useful!
      And yes, you are correct. It was a mistake on my part 😄 I'm using 'rb' more than once, and that too on FixedUpdate(). So, I should have cached it.

  • @vulpoaica5744
    @vulpoaica5744 หลายเดือนก่อน +1

    • @anandev
      @anandev  หลายเดือนก่อน

      🤖💖🐷❤️✨