Creating an FPS Controller in Unity (Movement, Footsteps, Jumping)

Поділитися
Вставка
  • Опубліковано 9 січ 2025

КОМЕНТАРІ • 68

  • @SpeedTutor
    @SpeedTutor  Рік тому +2

    ➡This Controller with the New Input System: ua-cam.com/video/b0AQ6IENZFg/v-deo.html
    🔥Unity Sales: bit.ly/UnitySalesHub
    🔥SpeedTutor Unity Store: bit.ly/STUnityStorePuzzlePacks
    🔥HUMBLE SAVINGS: bit.ly/HumbleBundleDeals

  • @Gurem
    @Gurem Рік тому +5

    Simply sublime base controller. Best one I've ever gotten from youtube.

    • @SpeedTutor
      @SpeedTutor  Рік тому

      I'm really happy that you found it useful! :) Good luck with your project too! :)

  • @davidmiles2055
    @davidmiles2055 Рік тому +3

    Love your tuts! Your voice and accent are great ;)

    • @SpeedTutor
      @SpeedTutor  Рік тому

      Thanks David, I really appreciate it my friend! :)

  • @mirfasiuddin2161
    @mirfasiuddin2161 Рік тому +1

    This tutorial is a lifesaver for aspiring game developers like me! 🙌🕹
    Creating a first-person shooter (FPS) controller from scratch can be daunting, but your step-by-step guide makes it seem much more manageable. You've explained everything, from movement to footstep sounds and jumping mechanics, which is amazingly understandable and easy to follow.
    I especially appreciate the attention to detail and the practical tips you've shared throughout the video. You're not just showing us how to make a first-person shooter (FPS) controller but also teaching us best practices and optimization techniques.
    I can't wait to implement this in my own Unity project. Thank you so much for sharing your knowledge and making game development more accessible! 🚀🎮

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      Thanks for coming to watch and give me your opinion, my friend! :) I try my best to lay it all out to make it easy to refer to and go back and learn things. Especially if you don't need the extra features. Are you working on anything at the moment?

    • @mirfasiuddin2161
      @mirfasiuddin2161 Рік тому

      @@SpeedTutor You're very welcome! Your dedication to creating informative and accessible content is evident, and it's much appreciated. As for my current projects, I'm continually improving my skills and knowledge, aiming to assist and provide valuable information wherever possible. If there's anything specific you'd like to know or discuss, Please feel free to ask-I'm here to help! 😊📚 #ContentCreation #KnowledgeSharing #AlwaysLearning

  • @angelawalsh7851
    @angelawalsh7851 Рік тому +1

    Thanks!

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      You're very welcome and I appreciate the kind thanks! :) How did you find me?

  • @SamNBCA
    @SamNBCA Рік тому +2

    Great video, One thing to address would be diagonal movement having a different velocity. Pressing 2 movements keys at once, [W] & [D] for example results in our character moving slightly faster than just pressing forward. There should be a step in there to normalize the input values before we apply the speed multiplier.

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      Oh that's a very fair point, thanks for pointing that out! I hope others will see this and take it into account. I appreciate you taking the time to watch and respond! :D

    • @SamNBCA
      @SamNBCA Рік тому +4

      If anyone is curious here's how I corrected the diagonal movement going faster than intended.
      void HandleMovement()
      {
      float speedMultiplier = Input.GetKey(sprintKey) ? sprintMultiplier : 1f;
      // Use Input.GetAxisRaw or the character will keep moving a few frames after button release.
      Vector3 horizontalMovement = new Vector3(Input.GetAxisRaw(horizontalMoveInput), 0, Input.GetAxisRaw(verticalMoveInput)).normalized;
      horizontalMovement = transform.rotation * horizontalMovement;

      HandleGravityAndJumping();
      currentMovement.x = horizontalMovement.x * walkspeed * speedMultiplier;
      currentMovement.z = horizontalMovement.z * walkspeed * speedMultiplier;

      characterController.Move(currentMovement * Time.deltaTime);
      }
      The important part is normalizing the input values before applying the speed multiplies. also you need to use "Input.GetAxisRaw" or the character will keep moving a few frames after button release.
      hope this helps.
      Cheers

    • @Gurem
      @Gurem Рік тому

      @@SamNBCA Using raw makes movement more responsive but choppy. The trade off may not be worth it but this is highly dependent on your use case. Please bear this in mind for anyone who is going to use this fix. Just remove the Raw keyword if you want the fluidity back.

    • @carlabalos3884
      @carlabalos3884 Рік тому

      @@Gurem I think just removing the Raw key word will not bring back the fluidity of the input. I tested it and the character still moves a bit longer than usual. His workaround fixed the normalizing issue which is important but the movement halt asap as the key is release. I found another workaround by just adjusting some settings on the input settings and the feel of using Input.GetAxis feels the same just my experience. The sweet spot for my gravity is 7 and 3 for sensitivity both horizontal/vertical. Here is the forum where I base my workaround. discussions.unity.com/t/character-keeps-moving-a-moment-after-i-release-input-keys/132547/2

  • @pyt3z
    @pyt3z Рік тому +1

    Wonderful tutorial Matt, I have been looking for something like this ever since I started with Unity game development when I was 11(Currently 14).

    • @SpeedTutor
      @SpeedTutor  Рік тому

      It's amazing that you're here and learning! Thanks for coming to watch, my friend! :)

    • @pyt3z
      @pyt3z Рік тому +1

      ​@@SpeedTutor Your welcome Matt. Keep up the good work and time you put in these tutorials. :)

  • @FallenAngel-yd7fp
    @FallenAngel-yd7fp 7 місяців тому +1

    Amazing guide. You are my Hero!

    • @SpeedTutor
      @SpeedTutor  7 місяців тому

      You're very welcome, my friend! :D What are you creating?

    • @FallenAngel-yd7fp
      @FallenAngel-yd7fp 7 місяців тому +1

      @@SpeedTutor i'm working on my project for college. we were poorly explained about the new input system, and there were no records or alternative sources.

    • @SpeedTutor
      @SpeedTutor  7 місяців тому +1

      I'm glad I could help you out! Best of luck with your college project.

  • @Wonder_Verse_Tech
    @Wonder_Verse_Tech Рік тому +2

    Keep up in this 🔥 I will follow along

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      Thanks, I hope you find it useful! :)

  • @veal225
    @veal225 8 місяців тому +1

    Great tutorial!

    • @SpeedTutor
      @SpeedTutor  8 місяців тому

      Thanks for checking this out! :)

  • @asafbenjaminov2635
    @asafbenjaminov2635 6 місяців тому +1

    Thanks for this tutorial! it helped me alot!
    I actually found a bug in the beggining of the video where you multiply each axis by the speed and multiplier but this creates a situation where when walking diagonally the speed is increased
    The solution i found was to create a direction vector from the inputs and then multiply the normalized vector by the speed float

    • @SpeedTutor
      @SpeedTutor  6 місяців тому

      Yes, you're exactly right! I did create a new version like this for the newer input system and I did fix that issue as I recall. Thanks for the thoughts though! :)

  • @lowHP_
    @lowHP_ Рік тому +2

    thanks for your valuable videos

    • @SpeedTutor
      @SpeedTutor  Рік тому

      You're very welcome, thanks for coming along to watch it! :D

  • @MrInvit
    @MrInvit Рік тому +2

    Need tutorial on how to fix Character Controller bugs: with slopes (bouncing and changing speed). Not only with perfect collider rectangles, but on surfaces with roughness (MeshCollider or multiple colliders), since on them the collider normal moves the character along itself, changing its movement. Stuck on edges and inclined surfaces when the collider tilt angle limit is exceeded. A character controller can loop with the collider on any inclined surface (even 89 degrees) and get stuck or jump from it.
    There are many tutors, where these problems are solved separately, but there is no one where they are all solved together. The solution of one problem affects another and breaks it.

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      Thanks very much for the suggestions, I'll see what I can do! :)

  • @adamabbott2014
    @adamabbott2014 9 місяців тому +1

    sorry, I can not understand about speed = transform.rotation* speed in 5:52. i comment this line. it looks object's moving well.

    • @SpeedTutor
      @SpeedTutor  9 місяців тому

      Awesome, I'm glad its up and running :)

  • @PostiveBalances
    @PostiveBalances Рік тому +2

    Hi, loving the tutorial, but im getting an error at 9.35 saying
    NullReferenceException: Object reference not set to an instance of an object
    fpsController.HandleRotation () (at Assets/Scripts/playerController.cs:60)
    fpsController.Update () (at Assets/Scripts/playerController.cs:36)

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      Are you missing any references in the inspector?

    • @PostiveBalances
      @PostiveBalances Рік тому +1

      @@SpeedTutor yep changed camera tag to "maincamera"

  • @Gorila-el8yw
    @Gorila-el8yw 6 місяців тому +1

    thank you you are the best

    • @SpeedTutor
      @SpeedTutor  6 місяців тому

      You're very welcome! :)

  • @ryanh.1346
    @ryanh.1346 Рік тому

    Would anyone have a solution to the little "sliding" I want it to stop immediately when I let go and not move for a short time after I release the button?

  • @Sewaskal
    @Sewaskal Рік тому

    underrated

  • @JBtheWARVillain
    @JBtheWARVillain Рік тому

    If you haven't done already, could you make a 3rd person controller also? Clean and clear tutorial again, thanks

    • @SpeedTutor
      @SpeedTutor  Рік тому +1

      I actually have a couple of tutorials in my description about that actually! :)

  • @FONORX
    @FONORX 11 місяців тому

    Landing sound after jumping... neeed

  • @genasols.r.l4910
    @genasols.r.l4910 Рік тому +1

    Good video, can it be used to handle slopes?

    • @SpeedTutor
      @SpeedTutor  Рік тому

      I think the CharacterController does take slopes into account by default without any extra ground work. As per the slope amount in the CharacterController. :) I'm not 100% though.

  • @masonmmmmunch847
    @masonmmmmunch847 Рік тому +1

    Great tutorial! I dont know if I mis-typed some code, but my character when standing still is unable to jump, do you know how I'd fix that?

    • @SpeedTutor
      @SpeedTutor  Рік тому

      I'm not sure without seeing some of the code, did you put the jumping method in the correct place?

    • @masonmmmmunch847
      @masonmmmmunch847 Рік тому

      it was to do with currentMovement.y in the handle gravity block. I dont know why but replacing the -0.5f with -1f instead seemed to do the job.@@SpeedTutor

  • @SGUDevs
    @SGUDevs 7 місяців тому

    what happen if its the same like person and a vehicle? or will i have to rewrite script but reducing certain things?

    • @SpeedTutor
      @SpeedTutor  7 місяців тому

      I'm not sure what you're asking?

    • @SGUDevs
      @SGUDevs 7 місяців тому

      @@SpeedTutorhaving different character types for this script to work with

  • @STYM-wx9mt
    @STYM-wx9mt Рік тому

    Can you make a tutorial for movement by touch input and virtual joystick 🕹

    • @Artifical_Deforum
      @Artifical_Deforum Рік тому +2

      Diztel magic has a fantastic tutorial already that uses unitys input system and their fps controller
      Once you understand how to use it and how it works you can apply it to anyone's controller for mobile.

    • @SpeedTutor
      @SpeedTutor  Рік тому

      That's pretty cool, I always recommend Rewired because it does it all without issue :)

  • @Huzzy267
    @Huzzy267 4 місяці тому

    My character just flies up when jumping my script is exactly the same any ideas

    • @SpeedTutor
      @SpeedTutor  4 місяці тому

      Do you have a rigidbody on your character?

  • @ayon...
    @ayon... Рік тому

    How do I create the sample scene

    • @SpeedTutor
      @SpeedTutor  Рік тому

      You can get that free on my website or my Unity store page :)

  • @Wonder_Verse_Tech
    @Wonder_Verse_Tech Рік тому +1

    🔥🔥🔥

  • @Survivor_Shelter
    @Survivor_Shelter 10 місяців тому

    it was 2024, and the dude is still using the crooked old system

    • @SpeedTutor
      @SpeedTutor  10 місяців тому

      I have a video in the description where I convert this for the new input system too. I just know people use both. :)

    • @Survivor_Shelter
      @Survivor_Shelter 10 місяців тому

      Please record a video on using the cinema machine and new input for the player, there are very few such videos@@SpeedTutor