3RD PERSON CONTROLLER in Unity - Player Movement
HTML-код
- Опубликовано: 9 янв 2021
- In this video (Episode 2) we implement the ability to move, and rotate our player in our game space!
► PLAYER MODEL & ANIMATIONS
drive.google.com/drive/folder...
► JOIN OUR DISCORD
/ discord
► SUPPORT ME ON PATREON!
/ sebastiangraves
► ASSET STORE PAGE (Animations & Models)
assetstore.unity.com/publishe...
► FOLLOW ME IN INSTAGRAM!
/ tragicallycanadian
► EPISODE 3
• 3RD PERSON CONTROLLER ...
Man, after watching like 10 tutorial series's now i feel like with this one i can actually create my game. Love you
FYI to future visitors to this video: Line 19 at 4:55 can potentially cause a minor bug where your characters forward speed will be reduced if you are pointing the camera down towards the ground or up towards the sky (this happened on my project, but may not happen to everyone since my setup is a little different). If you are running into a similar issue, try replacing this line with "moveDirection = new Vector3(cameraObject.forward.x, 0f, cameraObject.forward.z) * inputManager.verticalInput;"
Good luck with coding!
Perfect, I encountered this exact issue in the next video, exactly as you described. I've altered the line with your code and it's working great! Chef kiss!
Another option is switch positions of line 21 with 22 because this bug happens through the normalization of the vector including the Y Vector so if you normalize after you set Y to 0 it will do the exact same thing as what you suggest but slightly more readable.
Thanks for the tutorial. Love how you don't just say this does that and instead, actually explain things. Looking forward to the animations.
Thank you very much for giving us these detailed tutorial! I've been jumping from different tutorials because I want to learn the fundamentals not just getting things to work. Your series offer a clean and organized approach to handling inputs and movements. Definitely following all through!
One of the best movement tutorials out there! This is one of the only tutorials which explains player movement using the new Input system. Thank you
One of the only series on input systems that isn't either convoluted or corner case. Greatly appreciated!
This is one of the best movement methods I’ve seen on RUclips. You’re also teaching a lot of good habits
One year later....I am going through this again and understand the WHY so much more than i did last time. If you are new to UNity and C#, do this series then visit it again after a few more months of learning and i bet anything you get 2X from it what you did last time. Thanks again brother!
Another awesome video. Moving along in the series very nicely.
The best 3rd Person Character controller on YT. Not super updated but still handles all the necessary functions for a smooth moving character.
2:40 For the people who got confused: that "cameraObject.forward" is not the "Vector3.forward" (shorthand for Vector3(0, 0, 1))
When you use it on transform it means get the "Z" axis of transform.
Ive been looking so long for An easy Tutoreal to unerstand Job well done :D
Awesome series, the movement feels simple and good.
Literally the most underrated unity tutorial. So helpful
I was just about to come down here and say the same! These tutorials are BY FAR the MOST HELPFUL tutorials I HAVE EVER seen for Unity. He doesn't just tell us what to do, but he also explains it to us in a clear and easy to understand way.
Loving this so far!
was struggling to make 3rd person camera on my own, thanks for the help!!!
My offering to the feared algorithm. Thanks for taking the time to do these tutorials, Sebastian. It helps a lot.
Thank you for taking the time to write this my friend, cheers :^)
@@SebastianGraves hey i did it exactly like you did but my player dosent move when i press they input keys
@@bluflame5381 Most likely because velocity (speed) is set to 0
@@unitylearning8736 doesnt fix my issue. i have watched this video 67 times and i still cannot figure out why my player wont move. i get no error codes and i have made absolute certain the code is exact
any ideas?
@@theblazomatic2252 Most likely a problem with input manager, make sure your input has Vector2 value set, and the proper controls for WASD. Maybe you can make a small video demonstrating the issue and I can help you. Also, make sure that input manager is properly referenced where movement of playerInput is a direct event reference that reads the value of movement from playerInput, and converts to vector2 inside script
Worked very fine! Thank you for teaching nice and slow so anyone can understand :D
u juggle functions like a coding god
Thank you again for putting this tutorial series together.
strictly a style choice, but you can simplify some of your expressions:
moveDirection = moveDirection + camera.transform.right * inputManager.HorizontalInput;
can be simplified to:
moveDirection += camera.transform.right * inputManager.HorizontalInput;
same can be done for subtraction, multiplication, and division operations.
It took me 20 minutes to realize that "RigidBody" was not the same as "Rigidbody". Once I figured out stuff were case sensitive, though, it went smooth after that. Great video.
can u paste the code here
The reason why you handle movement or physics on the FixedUpdate is because theres where the physics frames are run through Unity, and are always consistent between frames, so you want your physics and movement to be consistent. Update is the framerate which if the game lags the time between frames can be longer and therefore less consistent, causing stutters or inconsistent calculations or you were running movement and physics through there.
Thanks for the awesome turtorial!
Loving it! Keep it up!
imagine not watching this whole series... ITS TO GOOD!!!!!!!!!!!
2024 and still mind blowing!!!
Thank you very much🙏
This is quite helpful, thank you.
exactly what i needed. no bs tutorial. ty
But because you made so much sense I wanna keep going. I just will have to find someone to walk it through with me. One o f the only videos out of the 50 I have watch which went slow and explained what was happening. Thanks and I will keep trying!
Thank you for your videos, much love.
This is awesome man, thank you so much!
Thank you Sebastian!
Please make some series on shooting weapon switching and inventory stuff (mobile based)
your videos are very much helpful
thanks in advance
Really Helpful, thanks
hi thx for your awesome videos
excellent work
If your Character isn't looking forward or Backward under the HandleRotation method on the PlayerLocomotion Script add a + infront of the = on targetDirection.....forward
and targetDirection...right
ex. Change
targetDirection = cameraObject.forward * inputManager.verticalInput;
targetDirection = cameraObject.right * inputManager.horizontalInput;
to
targetDirection += cameraObject.forward * inputManager.verticalInput;
targetDirection += cameraObject.right * inputManager.horizontalInput;
Absolute legend , thank you man
Man, I'm in love with your tutorials! Even someone as dumb as me can clearly understand everything! P.S. I would like to point out that the way the movement is handled in this video will make movement speed dependent on camera angle, which is not ideal, because with a camera controller it would change the speed of the player depending on camera angle. Hopefully this is fixed in future episodes. Cheers! I hope to see more!
If anyone needs a quick fix for the issue I mentioned, just do moveDirection.y = 0 BEFORE normalizing the vector. This should give a constant speed no matter what the camera angle is.
@@Valentin_Teslov thxs
16:05 may the algorithm gods Favour u bro
I HAVE FOUND A GOLD MINE! THE EXPLAINATION IS SOOOOO GOOOOOOOOOOD!!
Great tutorial!
Best tutorials ever
Hey man! Great helpful video! I was just wandering what the music for the intro was? It is so good!
So much better than the Dark Souls series of the channel, both in terms of clarity and the code itself.
The Dark Souls series really gets better as the series progresses, but you are correct. Compared to this, the beginning is very bumpy!
u deserve more subscriber
This was *super* helpful ngl
You sir are a gentleman and a scholar. Thank you for making this series, without it, i would struggle.
I just wanna leave a few words on FixedUpdate() for anyone who might need to hear it - FixedUpdate() is called at the beginning of each CPU cycle in which the game is run.
The call to FixedUpdate() happens *before* each frame draw. That means FixedUpdate() is a good place (time) to do physics calculations, before the frame is drawn - frames which reflect the changes made based on physics. Is moving a character physics? Of course it is, this is Unity 101, everything that happens in the engine is the result of physics being applied to objects.
When you want to move, or rotate, you have to apply forces to your player. The Quaternion API applies forces that rotate your character in a natural way - if you try to rotate the character yourself by using the rotation transform for example, you encounter a host of issues.
Cheers and Good luck on the path.
Thank you for sharing! :^)
FixedUpdate is framerate independent and it happens once every o.02 seconds which means it runs at constant 50 times a second cycle which makes it good for physics...but the rate of it is sort of arbitary and you can even change it from unity settings
OMG!!! you the next Brackeys
Very useful, thanks
Love it!
Good work ! Maybe a bit old, but still works also in 2024 under 2022.3 🙂
Today found myself rewatching this series so I can reformat it into a hierarchical state machine setup
this dude rocks!
For those of you with a custom model from blender, make sure that you apply transforms to your model before and while exporting it. Then after making it a game object with original prefab, make sure that your rig is facing the same way as your gameobject, or else it will rotate the wrong directions while moving
May i advise you to Number the episodes on the title so youtube sees them as a series and recomends the next one
great work :-)
Awesome!
great, thanks for the help
I Love You Man!!
Another comment mentioned the velocity slowdown when your camera is looking down caused by 4:55 which was a close answer but not quite right. The issue of moving slower when looking down is caused by camerObject.forward in line 19 because it takes the vector3 position of the camera 's blue axis and multiplies your verticalInput by it. To stop it from causing issues with velocity when looking down you should normalize cameraObject.forward and ALSO get rid of the cameraObject with (cameraObject.forward).normalized so the values will be just 1 or -1 instead of 0.34 which is the number gutting your running speed.
He didn't have this issue because he normalized his entire walk/run speed regardless of analog inputs, and then made specific speeds per animation instead of just using the raw input from a joystick. This change is crucial for platformers since players will want more control over how fast they go.
Edit: ALSO make sure you normalize your other cameraObject stuff too. You want your camera to give you a nice 1 or -1.
I really appreciate the explanation you do in these tutorials but my character just doesn't move and I don't know why. I am also curious how the camera correlates to our movement even though the camera itself doesn't know.
You just got new subscriber
Perfect!
Amazing.
For people using custom models, if for some reason your character is side-strafing all the time, never looking where you inteded. Your model just might be configured wrong, as it might be rotated on its own already. Just happened to me, where I forgot to apply transformations in blender :p
Thanks!
Thanks Man!
Thanks for the videos mate!
bro I really like your tutorial ;)
i had problems with the code but i used chat gpt so i fixed it :) thanks for the amazing tutorial tho
Does movementSpeed need to be multiplied by Time.deltatime, so it can be consistant at different frame rates as well?
Hello Sebastian I am curious how did you learn about unity? Do you just kind of create these videos as you learn the material to ?
I followed this all my code seems to match but it says my player manager scrip can't be found
Thx very much
Amazing
Thank you Sebastian for your tutorial video I've got everything right except how do you make your character touch the ground, mine keeps flying lol
Wait nvm I forgot to put my Rigidbody radius at 0.2 lol
Btw I have new problem how do you move your character, my character remains in idle lol
This entire playlist is soooo helpful, and easy to follow! I can't thank you enough for these videos! This is really cool, but I have a question. How come my character keeps moving after I release the keys? Is that what counter-movement is used for? Thanks again for these tutorials, they have been super useful!
Did you figure it out?
@@TheLegendarySandwich Um, you want to add a direction for movement right? Set the direction to 0 before yoy check for key presses, so if you arent pressing any, friction should start slowing you down.
Nice one great explanation brother for future please teach how to configure new input system with touch controls...
Legend
Hello There, all of these scripts used in the tutorial, can I use them for my 3D game to make my 3rd person controller?
I am feeling generous,
thank you
Another way to handle preventing the player from rotating until movement is pressed is to encase your transform.rotation = playerRotation; line in an if statement that checks to see if inputManager.verticalInput or inputManager.horizontalInput is nonzero, as below:
if (inputManager.verticalInput != 0 || inputManager.horizontalInput != 0)
{
transform.rotation = playerRotation;
}
I'm not sure which way is more efficient, anyone care to weigh in?
Anyway, thanks for the great tutorial series, Sebastian. You've earned my likes and subscribe. If you haven't done one already, I'd love to see a similar series using Unity's built in Character Controller rather than a Rigidbody. Cheers!
Hi, I have followed this meticulously, but my character faces directions when going left and right, but not when going forward or back... can anyone help?
Thank you so much for this video. One question though -- why does the new Input System consider the WASD movement to be on the XY plane, while the old input system considered WASD to be on the XZ plane?
Late reply, but Im guessing its probably something to do with making 2D development easier?
why not do Time.deltaTime on the players movement? why only on the rotation?
is the player locomotion script necessary at all if ur only coding for the wasd keys? at least the lines involving measuring the joystick for force, like this is my first time trying to code so im going to copy it down entirely so i dont fuck anything up lol but i also decided not to input all the left stick movement
Youre a god.
3:00
when i do this it comes with error that says "input manager is inaccessible duo to its protection level " pls how to fix it
im going through the video again but im getting errors foe the locomotion scripts for line 17 and the target rotation horizontal line
i am having this error: An abject reference is required for the non static field method or property inputManager.verticalInput.
And the same but horizontalInput. Please help
I realized that making folders and then dragging and dropping the said scripts or assets into more organized folders causes it to copy and therefore give you errors saying some code and declarations already exists.
Guys i need to ask. Do i have to change anything from this episode to make my player going backwards(but still facing forward) when pressing 'S' ? great tutorial btw ❤❤
I want to know tooo
Super!!!!
7:00 what difference does it make whether you put it between the moveDirection.y and Vector3 movementVelocity or not?
can anyone help me i followed along and i get my movement and vertical and horizontal values working but i get no movement from the player
I've been spending possibly more than two hours trying to solve an issue (resolved now); when my character landed on the plane, it started bouncing. I've been over so many things, replacing the capsule collider, checking code if something was wrong there, etc etc. Still bouncy.
It was the plane. The very normal plane with a mesh collider on it. Works perfectly fine with cube/box collider. Unity is damn strange sometimes (or I'm just too noob to understand why that doesn't work :p)!
its ok happens to everyone you hate the problem but the moment you solve it feels so goood good luck on your dev journey
I love these tutorials im having some problems with an CS0111 error on the PlayerManager script tho I would love to know what I'm doing wrong if anyone can help other than that I love your content keep it coming you inspired me to try making games
I had same problem. Fixed by making sure the correct class was being used.
thansk !
What theme do you use for Visual Studio?