Watching the video I thought "This is great - I should put that into a cheat sheet for quick reference"...and then you ended with "Here's a cheat sheet." Thank you! ❤
For my own top down game I use rigid body with AddForce. It's by far the most flexible just because it plays nicely with the physics system. As you said, you can add knockback or other physics based things directly on top of the player's movement... so things can push the player around while the player can still move. For my player controller, I didn't add artificial acceleration/deceleration and just used the Rigidbody2D settings. I created a frictionless material, then set Mass to 150, Linear Drag to 40 and Angular Drag to 0.05. Then when I add enough force to the rigidbody, it will move perfectly. There is no acceleration/deceleration, so when you move around it's 1:1 and feels very responsive. The character moves at full speed immediately and stops instantly, but has all the benefits of physics collisions. The movement is basically Legend of Zelda top down movement but with physics. I think what trips most people up is that they don't mess with the Rigidbody 2D settings enough, so they think using AddForce just results in a floaty mess, but you can tweak these settings to be perfect for the movement you're looking to create.
This is a really solid video for understanding the difference between the types of movements. And would be a great reference for any Unity developers starting a new project and deciding which route to go. I will be saving this and referring to it at each project as a quick refresher. Good work!
I wish you posted this a week ago when I was having issues with applying a knockback while my movement handling was in Update. I ended up figuring out on my own that I needed fixedUpdate to get it to work. Just find it funny that I was dealing with this issue that took me hours to figure out for you to only post this video today lmao! Good stuff!
Nice to have a video seeing it explained this quick and well. I was always struggling with this topic. It definetly gets into my GameDev Playlist! :) Thanks. Just have to figure out what's different for my 3D games.
One thing that's a bit more advanced that helps with any of these, but especially with the rb.velocity method is using a Finite State Machine to set the velocity based on state changes. So Idle is defined as velocity zero, Jump is defined as velocity.y being positive, Falling as velocity.y being negative, etc. Alternatively, you could use GOAP as well, which is even more advanced.
It's nice to see these side by side. I generally knew the basics of each, but the pros and cons are really handy. Thanks! Are there any notable differences in these from 2d to 3d?
Yes, there are. In 3D there is vertical movement like stairs and uneven ground. The unity CharacterController briefly mentioned at 07:28 is made specifically for that purpose. In 3D first person, the camera is linked to the character position which means that even a little unevenness in movement looks absolutely horrible. Standing on moving objects like elevators is often done by temporarily parenting the player but physical movement happens in FixedUpdate and so any combination of player character being moved by other objects gets kinda tricky. Depending on the artstyle and camera perspective, the syncing of animations and movement requires more work and using root animations, where the animation system drivers the movement, may be required for it to look good.
Nice video! One "problem" is that you are not mentioning anything about linear drag that interacts with forces applied to a rigid body! It could be useful to have an update on this topic! :)
Nice video, it really helps understanding movement for beginners. Every other tutorial for moving just chooses a method and doesnt tell you about the other ones
You are the best of the best explaining things. I hope you can upload a tutorial for picking objects in 2D and in 3D not using RayCast, it cost me a lot to understand the power of the trigers.
There is also one good method for tilebased games that uses interpolation between discrete tile positions.Its fast, since no physics calculations are needed and positions are always exact.
i see you have input manager up there on the 4th option, are you using the new input system for just the forth option? or are you using it for all of them? also which of these four are best for combat? such as dashing, dodging, and knockback?
Personally, I love rb.Velocity. You need to modify your thinking/setup such that it's open to forces being added. Rather than setting the velocity directly through movement, you should have player's intended movement be one part of setting a velocity. With it getting either multiplied. subtracted, or added with to other forces that intended to interact with the Player.
Is there a way to emulate canvas-like selection but with a game object? I am trying to emulate the feel of cursor hopping from one item to the other. But it is really fast (fps fast), so I implemented it as a coroutine which delays the next move. I wonder if there's a better way to do it.
Beginner comment here: That InputManager.Movement looks like it should be a vector based on the x and y input. Where is that defined? I don't seem to have that input capture method available to me in my script.
that's based on a manual input script I created. (You could check out the Top-down movement tutorial, it's exactly the same) - Just a personal preference of mine
What about the velocity one? You didn't tell how to overcome the overriding of it and using add force a long side it... I was once stuck because of this thing couldn't find why or how to resolve it when manipulating the velocity directly.
Using the animators root motion is also a way to control. In modern realistic games with a visible character, that is the primary way to do it because it syncs movement and animations the best. One big issue is also the linking between hero and camera. In 2D that is not muhc of an issue as the camera is external and its so easy to tween. 3D first person, holy fuck that is a mess.
Yes. rb.AddForce is the easiest to add a dashing mechanic to it, but the others are all very possible. I use rb.Velocity and added an if(dashing == true){dash code}else{move code} in the fixed update.
To answer the question, we just have to think about what it means to actually dash. When we say dash, we mean a sudden and usually temporary burst of speed. Each of these methods is just a way of applying speed. So you would just use that method to raise the speed and then wait a bit and lower it back down again.
02:57 You don't have to multiply by neither deltaTime nor fixedDeltaTime. In FixedUpdate their value remain the same every call so its an unnecessary calculation. Both of them always return 0.02f by default.
If we are technically pendantic, then no. The FixedUpdate does not run at 50FPS default, it runs as often as it is required before the visual frame to ensure that physics happen in small enough steps for the physics algorithms to work. The FixedUpdate-Calls are also not equidistant in their time of appearence. If you search the unity forums, you can find people doing statistics and standard deviations of the true frequency and deltas of FixedUpdate-Calls depending on actual Update-FPS. Also, the FixedUpdate frequency can be changed, but even changing it to match 60FPS on an 60FPS locked games does not ensure a 1:1 between Update() and FixeUpdate().
@@sealsharp I didn't say that its runs at 50fps but the value is never changed during the runtime. So the value is constant and unnecessary to multiply with it. You may log the value and see its never change.
At 07:28 our hero, the CharacterController get's a mention. In a 3D game, this would be weird to leave out since CharacterController is a solution to so many complications on 3D.
Watching the video I thought "This is great - I should put that into a cheat sheet for quick reference"...and then you ended with "Here's a cheat sheet." Thank you! ❤
For my own top down game I use rigid body with AddForce. It's by far the most flexible just because it plays nicely with the physics system. As you said, you can add knockback or other physics based things directly on top of the player's movement... so things can push the player around while the player can still move.
For my player controller, I didn't add artificial acceleration/deceleration and just used the Rigidbody2D settings. I created a frictionless material, then set Mass to 150, Linear Drag to 40 and Angular Drag to 0.05. Then when I add enough force to the rigidbody, it will move perfectly. There is no acceleration/deceleration, so when you move around it's 1:1 and feels very responsive. The character moves at full speed immediately and stops instantly, but has all the benefits of physics collisions. The movement is basically Legend of Zelda top down movement but with physics.
I think what trips most people up is that they don't mess with the Rigidbody 2D settings enough, so they think using AddForce just results in a floaty mess, but you can tweak these settings to be perfect for the movement you're looking to create.
This is a really solid video for understanding the difference between the types of movements. And would be a great reference for any Unity developers starting a new project and deciding which route to go. I will be saving this and referring to it at each project as a quick refresher. Good work!
I wish you posted this a week ago when I was having issues with applying a knockback while my movement handling was in Update. I ended up figuring out on my own that I needed fixedUpdate to get it to work. Just find it funny that I was dealing with this issue that took me hours to figure out for you to only post this video today lmao! Good stuff!
This is a great reference video, definitely bookmarking. Thanks 🙂
Super-useful video thanks! I'm reworking my object movement today in my solo-indie-dev game, RoadHouse Manager, and this has been so helpful.
This is called BEST PRACTICE!
Learn this and you're half way to make a good game my friends! 😎👍
Nice to have a video seeing it explained this quick and well. I was always struggling with this topic. It definetly gets into my GameDev Playlist! :) Thanks. Just have to figure out what's different for my 3D games.
One thing that's a bit more advanced that helps with any of these, but especially with the rb.velocity method is using a Finite State Machine to set the velocity based on state changes. So Idle is defined as velocity zero, Jump is defined as velocity.y being positive, Falling as velocity.y being negative, etc. Alternatively, you could use GOAP as well, which is even more advanced.
very true, i mainly use rb.velocity along with a finite state machine as mentioned. Haven't tried the GOAP yet though
It's nice to see these side by side. I generally knew the basics of each, but the pros and cons are really handy. Thanks!
Are there any notable differences in these from 2d to 3d?
Yes, there are.
In 3D there is vertical movement like stairs and uneven ground. The unity CharacterController briefly mentioned at 07:28 is made specifically for that purpose.
In 3D first person, the camera is linked to the character position which means that even a little unevenness in movement looks absolutely horrible. Standing on moving objects like elevators is often done by temporarily parenting the player but physical movement happens in FixedUpdate and so any combination of player character being moved by other objects gets kinda tricky.
Depending on the artstyle and camera perspective, the syncing of animations and movement requires more work and using root animations, where the animation system drivers the movement, may be required for it to look good.
Very informative. Appreciated
Nice video!
One "problem" is that you are not mentioning anything about linear drag that interacts with forces applied to a rigid body! It could be useful to have an update on this topic! :)
Nice video, it really helps understanding movement for beginners. Every other tutorial for moving just chooses a method and doesnt tell you about the other ones
You are the best of the best explaining things. I hope you can upload a tutorial for picking objects in 2D and in 3D not using RayCast, it cost me a lot to understand the power of the trigers.
Loved the video! I'd actually be interested in coverage of the Character Controller if you get around to making a 3D version of this vid.
nice video! RB.Velocity ftw!
There is also one good method for tilebased games that uses interpolation between discrete tile positions.Its fast, since no physics calculations are needed and positions are always exact.
i see you have input manager up there on the 4th option, are you using the new input system for just the forth option? or are you using it for all of them? also which of these four are best for combat? such as dashing, dodging, and knockback?
Personally, I love rb.Velocity. You need to modify your thinking/setup such that it's open to forces being added. Rather than setting the velocity directly through movement, you should have player's intended movement be one part of setting a velocity. With it getting either multiplied. subtracted, or added with to other forces that intended to interact with the Player.
So question I been looking for is why do others use vectors? Instead of using translate( 0, 0, 1) or whatever.
Is there a way to emulate canvas-like selection but with a game object? I am trying to emulate the feel of cursor hopping from one item to the other. But it is really fast (fps fast), so I implemented it as a coroutine which delays the next move. I wonder if there's a better way to do it.
great tut!
dude you are awesome
Beginner comment here: That InputManager.Movement looks like it should be a vector based on the x and y input. Where is that defined? I don't seem to have that input capture method available to me in my script.
that's based on a manual input script I created. (You could check out the Top-down movement tutorial, it's exactly the same) - Just a personal preference of mine
What about the velocity one? You didn't tell how to overcome the overriding of it and using add force a long side it... I was once stuck because of this thing couldn't find why or how to resolve it when manipulating the velocity directly.
Using the animators root motion is also a way to control. In modern realistic games with a visible character, that is the primary way to do it because it syncs movement and animations the best.
One big issue is also the linking between hero and camera. In 2D that is not muhc of an issue as the camera is external and its so easy to tween. 3D first person, holy fuck that is a mess.
Is it possible to make a dash with all of this methods?
Yes. rb.AddForce is the easiest to add a dashing mechanic to it, but the others are all very possible. I use rb.Velocity and added an if(dashing == true){dash code}else{move code} in the fixed update.
Yup, u stop the movement code when dashing and start the movement code when done with dashing
To answer the question, we just have to think about what it means to actually dash. When we say dash, we mean a sudden and usually temporary burst of speed. Each of these methods is just a way of applying speed. So you would just use that method to raise the speed and then wait a bit and lower it back down again.
02:57 You don't have to multiply by neither deltaTime nor fixedDeltaTime. In FixedUpdate their value remain the same every call so its an unnecessary calculation. Both of them always return 0.02f by default.
If we are technically pendantic, then no.
The FixedUpdate does not run at 50FPS default, it runs as often as it is required before the visual frame to ensure that physics happen in small enough steps for the physics algorithms to work. The FixedUpdate-Calls are also not equidistant in their time of appearence.
If you search the unity forums, you can find people doing statistics and standard deviations of the true frequency and deltas of FixedUpdate-Calls depending on actual Update-FPS.
Also, the FixedUpdate frequency can be changed, but even changing it to match 60FPS on an 60FPS locked games does not ensure a 1:1 between Update() and FixeUpdate().
@@sealsharp I didn't say that its runs at 50fps but the value is never changed during the runtime. So the value is constant and unnecessary to multiply with it. You may log the value and see its never change.
Official examples include multiplying by Time.fixedDeltaTime,docs.unity.cn/cn/2022.1/ScriptReference/Rigidbody2D.MovePosition.html
No charactercontroller ?
At 07:28 our hero, the CharacterController get's a mention. In a 3D game, this would be weird to leave out since CharacterController is a solution to so many complications on 3D.
@@sealsharp thanks i didn't watch the video cuz i wasn't interested in other methods
First