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 ...

Комментарии • 306

  • @Culix_Verses
    @Culix_Verses 9 дней назад +4

    Man, after watching like 10 tutorial series's now i feel like with this one i can actually create my game. Love you

  • @RacarCatilla
    @RacarCatilla 2 года назад +61

    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!

    • @clancycunningham4118
      @clancycunningham4118 2 года назад +2

      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!

    • @Peidobolhas
      @Peidobolhas Год назад +11

      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.

  • @_SF_Media
    @_SF_Media 3 года назад +17

    Thanks for the tutorial. Love how you don't just say this does that and instead, actually explain things. Looking forward to the animations.

  • @noicenoise8718
    @noicenoise8718 2 года назад +3

    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!

  • @duelator2813
    @duelator2813 2 года назад

    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

  • @olqb9532
    @olqb9532 3 года назад

    One of the only series on input systems that isn't either convoluted or corner case. Greatly appreciated!

  • @petermoss7387
    @petermoss7387 2 года назад

    This is one of the best movement methods I’ve seen on RUclips. You’re also teaching a lot of good habits

  • @brianromano4152
    @brianromano4152 Год назад +4

    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!

  • @stephenq24
    @stephenq24 2 года назад

    Another awesome video. Moving along in the series very nicely.

  • @CronoBJS
    @CronoBJS Год назад

    The best 3rd Person Character controller on YT. Not super updated but still handles all the necessary functions for a smooth moving character.

  • @MehmetSarkd
    @MehmetSarkd Год назад +7

    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.

  • @spiderdlh9905
    @spiderdlh9905 2 года назад +1

    Ive been looking so long for An easy Tutoreal to unerstand Job well done :D

  • @-BRODEN
    @-BRODEN 3 года назад

    Awesome series, the movement feels simple and good.

  • @bronze3336
    @bronze3336 3 года назад +25

    Literally the most underrated unity tutorial. So helpful

    • @thepman3798
      @thepman3798 2 года назад

      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.

  • @user-ry3mu4ov1i
    @user-ry3mu4ov1i 7 месяцев назад

    Loving this so far!

  • @REVOLV3
    @REVOLV3 9 месяцев назад +1

    was struggling to make 3rd person camera on my own, thanks for the help!!!

  • @FeyFen
    @FeyFen 3 года назад +8

    My offering to the feared algorithm. Thanks for taking the time to do these tutorials, Sebastian. It helps a lot.

    • @SebastianGraves
      @SebastianGraves  3 года назад

      Thank you for taking the time to write this my friend, cheers :^)

    • @bluflame5381
      @bluflame5381 Год назад

      @@SebastianGraves hey i did it exactly like you did but my player dosent move when i press they input keys

    • @unitylearning8736
      @unitylearning8736 Год назад

      @@bluflame5381 Most likely because velocity (speed) is set to 0

    • @theblazomatic2252
      @theblazomatic2252 Год назад

      @@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?

    • @unitylearning8736
      @unitylearning8736 Год назад

      @@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

  • @brunomedeiros4533
    @brunomedeiros4533 3 года назад +1

    Worked very fine! Thank you for teaching nice and slow so anyone can understand :D

  • @monkeyrobotsinc.9875
    @monkeyrobotsinc.9875 3 года назад +13

    u juggle functions like a coding god

  • @darkstarmike85
    @darkstarmike85 3 года назад

    Thank you again for putting this tutorial series together.

  • @Wolfie5309
    @Wolfie5309 2 года назад +1

    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.

  • @EndlessMystify
    @EndlessMystify Месяц назад +1

    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.

  • @joshuamalcolm2807
    @joshuamalcolm2807 2 года назад +1

    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.

  • @medad5502
    @medad5502 Месяц назад

    Thanks for the awesome turtorial!

  • @brianromano4152
    @brianromano4152 2 года назад

    Loving it! Keep it up!

  • @xdcretin-_-7363
    @xdcretin-_-7363 3 года назад +1

    imagine not watching this whole series... ITS TO GOOD!!!!!!!!!!!

  • @marvinrosales3483
    @marvinrosales3483 Месяц назад

    2024 and still mind blowing!!!
    Thank you very much🙏

  • @ahmettahaaltug1746
    @ahmettahaaltug1746 2 года назад

    This is quite helpful, thank you.

  • @AetherXIV
    @AetherXIV 2 года назад

    exactly what i needed. no bs tutorial. ty

  • @jameswilliams5143
    @jameswilliams5143 3 года назад +1

    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!

  • @titchc3657
    @titchc3657 Год назад

    Thank you for your videos, much love.

  • @AaronAsherRandall
    @AaronAsherRandall 2 года назад

    This is awesome man, thank you so much!

  • @garybuchert7005
    @garybuchert7005 Год назад

    Thank you Sebastian!

  • @muhammadahmadyousaf2824
    @muhammadahmadyousaf2824 3 года назад +2

    Please make some series on shooting weapon switching and inventory stuff (mobile based)
    your videos are very much helpful
    thanks in advance

  • @conorchambers8671
    @conorchambers8671 3 года назад

    Really Helpful, thanks

  • @Trypthophan
    @Trypthophan 6 месяцев назад

    hi thx for your awesome videos

  • @MCCAIN867
    @MCCAIN867 3 года назад

    excellent work

  • @suede44
    @suede44 Год назад +6

    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;

    • @BB-xb2di
      @BB-xb2di 5 месяцев назад

      Absolute legend , thank you man

  • @Valentin_Teslov
    @Valentin_Teslov 3 года назад +1

    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!

    • @Valentin_Teslov
      @Valentin_Teslov 3 года назад +4

      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.

    • @harharrr9810
      @harharrr9810 2 года назад

      @@Valentin_Teslov thxs

  • @tari0ty
    @tari0ty Год назад +1

    16:05 may the algorithm gods Favour u bro

  • @shazboi
    @shazboi 2 года назад

    I HAVE FOUND A GOLD MINE! THE EXPLAINATION IS SOOOOO GOOOOOOOOOOD!!

  • @ProductDesignGuru
    @ProductDesignGuru 2 года назад

    Great tutorial!

  • @SpoonTaco
    @SpoonTaco 3 года назад

    Best tutorials ever

  • @arthxrbeats
    @arthxrbeats 7 месяцев назад

    Hey man! Great helpful video! I was just wandering what the music for the intro was? It is so good!

  • @changming8227
    @changming8227 Год назад

    So much better than the Dark Souls series of the channel, both in terms of clarity and the code itself.

    • @SebastianGraves
      @SebastianGraves  Год назад

      The Dark Souls series really gets better as the series progresses, but you are correct. Compared to this, the beginning is very bumpy!

  • @lanha3385
    @lanha3385 9 месяцев назад

    u deserve more subscriber

  • @JLee118
    @JLee118 2 года назад

    This was *super* helpful ngl

  • @crispy6532
    @crispy6532 3 года назад +8

    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.

    • @SebastianGraves
      @SebastianGraves  3 года назад +1

      Thank you for sharing! :^)

    • @teemuleppa3347
      @teemuleppa3347 2 года назад +3

      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

  • @owigao
    @owigao 3 года назад

    OMG!!! you the next Brackeys

  • @iDmitryYakovlev
    @iDmitryYakovlev 3 года назад

    Very useful, thanks

  • @fortnitekiddy1315
    @fortnitekiddy1315 2 года назад

    Love it!

  • @DieterSoost
    @DieterSoost 2 месяца назад

    Good work ! Maybe a bit old, but still works also in 2024 under 2022.3 🙂

  • @sbtoonz1358
    @sbtoonz1358 Год назад

    Today found myself rewatching this series so I can reformat it into a hierarchical state machine setup

  • @sametayaz4891
    @sametayaz4891 6 месяцев назад

    this dude rocks!

  • @emi_on_youtube1380
    @emi_on_youtube1380 3 месяца назад

    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

  • @manuelsoares4343
    @manuelsoares4343 3 года назад +3

    May i advise you to Number the episodes on the title so youtube sees them as a series and recomends the next one

  • @joseluisRueda
    @joseluisRueda 2 года назад

    great work :-)

  • @morganw2535
    @morganw2535 2 года назад

    Awesome!

  • @seandobson2682
    @seandobson2682 2 года назад

    great, thanks for the help

  • @sufyaanali
    @sufyaanali 3 года назад

    I Love You Man!!

  • @treymtz
    @treymtz Год назад +1

    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.

  • @DeBlueGOD
    @DeBlueGOD Год назад

    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.

  • @edawkingyoutube4004
    @edawkingyoutube4004 Год назад

    You just got new subscriber

  • @Niko_3D
    @Niko_3D 2 года назад

    Perfect!

  • @paddybanerjee9211
    @paddybanerjee9211 2 года назад

    Amazing.

  • @maestro7619
    @maestro7619 8 месяцев назад

    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

  • @Makkara91
    @Makkara91 4 месяца назад

    Thanks!

  • @TheJakeblake
    @TheJakeblake 6 месяцев назад

    Thanks Man!

  • @w0tnessZA
    @w0tnessZA Год назад

    Thanks for the videos mate!

  • @992darus
    @992darus 2 года назад

    bro I really like your tutorial ;)

  • @bamanii
    @bamanii Год назад

    i had problems with the code but i used chat gpt so i fixed it :) thanks for the amazing tutorial tho

  • @allcodex825
    @allcodex825 2 года назад +1

    Does movementSpeed need to be multiplied by Time.deltatime, so it can be consistant at different frame rates as well?

  • @idcemail123
    @idcemail123 Год назад

    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 ?

  • @jasonbrinkman615
    @jasonbrinkman615 Год назад +2

    I followed this all my code seems to match but it says my player manager scrip can't be found

  • @studywithjimi
    @studywithjimi 2 года назад

    Thx very much

  • @crimson279
    @crimson279 2 года назад

    Amazing

  • @M_PEREZIMBERNARDBORNTPEREZ
    @M_PEREZIMBERNARDBORNTPEREZ 3 года назад +3

    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

  • @hyphen8d725
    @hyphen8d725 2 года назад +3

    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!

    • @TheLegendarySandwich
      @TheLegendarySandwich 7 месяцев назад +1

      Did you figure it out?

    • @hyphen8d725
      @hyphen8d725 7 месяцев назад +1

      @@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.

  • @saadbutt2186
    @saadbutt2186 3 года назад

    Nice one great explanation brother for future please teach how to configure new input system with touch controls...

  • @concernedcitizen9101
    @concernedcitizen9101 5 месяцев назад

    Legend

  • @Kingrio22
    @Kingrio22 2 года назад

    Hello There, all of these scripts used in the tutorial, can I use them for my 3D game to make my 3rd person controller?

  • @kalpolproductions8558
    @kalpolproductions8558 2 года назад

    I am feeling generous,
    thank you

  • @mikamuestudios
    @mikamuestudios 3 месяца назад

    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!

  • @roucifer7761
    @roucifer7761 Год назад +2

    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?

  • @harrison298
    @harrison298 3 года назад +2

    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?

    • @hizander
      @hizander 2 года назад

      Late reply, but Im guessing its probably something to do with making 2D development easier?

  • @skelettman
    @skelettman Год назад +1

    why not do Time.deltaTime on the players movement? why only on the rotation?

  • @purpleguyfromfnaf0
    @purpleguyfromfnaf0 Год назад

    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

  • @Bedo1012
    @Bedo1012 2 года назад

    Youre a god.

  • @dabrnii7854
    @dabrnii7854 Месяц назад +1

    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

  • @joshuabouatise5173
    @joshuabouatise5173 7 месяцев назад

    im going through the video again but im getting errors foe the locomotion scripts for line 17 and the target rotation horizontal line

  • @perz4080
    @perz4080 2 года назад

    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

  • @theroyalbubble1500
    @theroyalbubble1500 Год назад

    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.

  • @kostasalexakhs2271
    @kostasalexakhs2271 2 года назад +3

    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 ❤❤

  • @masterpirates1497
    @masterpirates1497 Год назад

    Super!!!!

  • @viraj3944
    @viraj3944 4 месяца назад

    7:00 what difference does it make whether you put it between the moveDirection.y and Vector3 movementVelocity or not?

  • @paulscott3083
    @paulscott3083 2 года назад +1

    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

  • @RaineAlgessar
    @RaineAlgessar Год назад

    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)!

    • @simoouss7100
      @simoouss7100 Год назад

      its ok happens to everyone you hate the problem but the moment you solve it feels so goood good luck on your dev journey

  • @SnakeRaptor
    @SnakeRaptor 3 года назад +3

    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

    • @thechadnesss5197
      @thechadnesss5197 Год назад

      I had same problem. Fixed by making sure the correct class was being used.

  • @luckasberguecioebensperger1665
    @luckasberguecioebensperger1665 Месяц назад

    thansk !

  • @MrKhiar-pq3ri
    @MrKhiar-pq3ri 2 года назад

    What theme do you use for Visual Studio?