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.
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?
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 😊
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.
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!
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
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 😊
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!
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.
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 😊
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.
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.
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.
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.
Wow thank you... This means a lot to me
The final quote on how we are not breaking physics laws but altering the nature of it to our needs is brilliant
Yessss! Thank you so much for the compliment! i'm glad that writing scripts beforehand proved to be useful! 🤓 Ty once again
Quite late but consider making a full playlist of this.
Loved the examples in-game. :)
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?
This is one of the best videos on rigidbody I've seen! Well done!
Thank you so much!! This means a lot! 🥹♥️
explanation between Mass and Drag in relation to freefall was very helpful; thanks for this vid!
Woah! 🤩 I'm glad it was helpful!
@@anandev Very helpful; trying to figure out a nice combat system/character controller using rigidbody over here!
Your video edit is spot on, the visual examples make everything quite easy to understand. Great job, many thanks :)
I'm glad that the 2 months of editing (which included 2 whole retakes) was totally worth it 😃 Happy that the video helped!
This is mad underrated I learned a lot of stuff from this
Woah! I'm happy that this was useful! I'm glad me spending time on it was worth it! Tysm! ❤
I hope your channel grows fast because these are very well made videos :) very clean and easy to understand :)
Aw! Thank you so much... It means a lot 🥰
An ultimate tutorial indeed. this answered all questions i had regarding physics!!
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 😊
Those drawings are really cute and as I have said before the production value is top
Woahhh!! This video took a month to make, and I'm glad you feel that way 🥰
OMG thank you so much just the first part about the collisions helped me solve multiple problems I had!
Yayy!! I'm glad it helped!
arguably the best explanation EVER!!!
Thank you so much!! It means a lot 🥰
brother you put in so much useful info in so little time
thank you
Awww! This made my evening! Thank you very much and I'm glad the video was useful! 😁
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.
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.
Great Efforts and nicely explained
Thanks a lot, and I'm glad you liked it
شكرا جدا على هذا الفيديو الرائع جدا أتمنى لك الافضل يا صديقي
Thank you very much for the kind words! 😊
Great great great tutorial! I’m definitely going to reference this again.
Yaaayy! Glad the video was useful 🤗
Thank you so much for this great video. This video helps to solve my problems.
Thank you so much for taking your time to comment this 🤗♥️ I'm glad this was useful
makes it all look easy... great tutorial
Thank you! Cheers! I'm glad it helps!
sheeesh, this channel is great. Explanations are pretty clear.
Aww 🥰 I'm glad you think so. Thank you so much
This is so well explained!! Thanks alot
Thank you so much! I'm glad the video was useful 😃
Thank you, that was super informative i learned soo much
Thank you for taking your time to let me know 😭♥️ I'm glad the video was useful
What a beautiful tutorial. Thank you! Subbed,, Liked and Commented!
Thank you sooo much 🥹❤️ You made my day, this means a lot
Also I forgot, I'm glad the video was useful.
@@anandev indeed.
Very good video, thank you very much!
Yay! I'm glad it was useful!
Thank you veryyy much, you're so good !
Yayy! I'm happy I could help! 🤗
Incredible video!!
Thank you so much! I'm glad the video is useful!
Very good video. Thank you 🙏
Thank you too!
Simple the best tips ever!
Thank you so much!! I'm glad you've found it useful
Thanks great video.
Thank you so much for watching. I'm glad it's useful 😃
I didn't know that rigidBody physics update at a fixed 50/s rate. Damn.
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.
Rigidbody has a role in detecting collisions.... (OnCollisionEnter)
Yes! Collision and Trigger Events are only registered when one of the two bodies contain a Rigidbody! 😸
Really good video.
Thank you so much 😊
Love it.
Thank you so much 😊 Glad you love it!
great video!
Thanks! I hope it was useful! 😊
You are King
We are all KINGS 👑
nice tutorial!
Thank you so much! I'm glad it is useful!
Great video!
Thanks! Glad you enjoyed it 😃
Thanks mate
I'm glad the video was helpful ☺
Great 👍👍 make other video about to think logic of games and code it
Thanks! 🥰 Do you have any specific game in mind?
@@anandev ludo
@@abg2487 On it! Sorry for the late reply! Didn't get the notification for some reason.
good video sir
Thanks! Glad the video was useful!
sir great work please upload character movement script explain
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!
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
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 😊
@@anandev thanks! i didn't know physics worked like that in unity
Just a suggestion that you should lower the volume of the popping noises, they get distracting. Great content, though.
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!
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.
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 😊
Subscribe , very good my friend! Loved it!
Thank you so much! It means a lot ♥️
Why does the velocity in the rigidbody component have coordinates?
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.
@@anandev Thank you!
You're welcome 🤗
I cant seem to find the info panel in my unity editor. HELP!!!
There is this window called Physics Debugger, the info panel moved over there in the later versions of Unity 2022
Oh Thank you! 👌🏽
You're welcome! 😊
😍
Thank you! 🥰
man i love Indians, thanks man :)
Haha! It's my pleasure 😁
That tongue roll tho
Yes it's my signature rizz move 🤭😎
you saved my life
and my wife
Well, I guess I can add "life saver" to my resume now!
🤩😍
Thank you 😇❤
RigidBody ou Character Controller para movimento de players
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.
hallo your computer has virus
My computer also has anti-virus
@@anandev copege
@@uhohwhy haha sorry
bro "Anan" means "Your Mother" in Turkish 💀💀
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 😂
@@anandev 😄 Nice video btw thanks
Thank you so much! Me glad the video is useful! 😸
too much sound effects and pops i cant watch
Yeah it was an honest mistake! I'll make sure to not repeat it ☺️
Excellent video ! I've learned a lot in a short time, thx ! :)
5:16 Rigidbody rb => GetComponent(); Isn't better to cache it ?
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.
🤖💖🐷❤️✨