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

Поделиться
HTML-код
  • Опубликовано: 31 янв 2025

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

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

    ➡This Controller with the New Input System: ruclips.net/video/b0AQ6IENZFg/видео.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! :)

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

  • @davidmiles2055
    @davidmiles2055 Год назад +3

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

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

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

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

    Thanks!

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

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

  • @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. :)

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

    • @VaderPepe
      @VaderPepe 22 дня назад

      @@SamNBCA This is another way to do without using axis raw
      void HandleMovement()
      {
      float speedMultiplier = Input.GetKey(sprintKey) ? sprintMultiplier : 1f;
      float verticalInput = Input.GetAxis(verticalMoveInput);
      float horizontalInput = Input.GetAxis(horizontalMoveInput);
      Vector3 movementInput = new Vector3(horizontalInput, 0, verticalInput);
      if (movementInput.magnitude > 1)
      {
      movementInput.Normalize();
      }
      Vector3 movement = movementInput * walkSpeed * speedMultiplier;
      movement = transform.rotation * movement;
      HandleGravityAndJumping();
      currentMovement.x = movement.x;
      currentMovement.z = movement.z;
      characterController.Move(currentMovement * Time.deltaTime);
      }

  • @FallenAngel-yd7fp
    @FallenAngel-yd7fp 8 месяцев назад +1

    Amazing guide. You are my Hero!

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

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

    • @FallenAngel-yd7fp
      @FallenAngel-yd7fp 8 месяцев назад +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 9 месяцев назад +1

    Great tutorial!

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

      Thanks for checking this out! :)

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

    thanks for your valuable videos

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

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

  • @asafbenjaminov2635
    @asafbenjaminov2635 7 месяцев назад +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  7 месяцев назад

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

  • @ToineMMXI
    @ToineMMXI 3 дня назад +1

    Did you also make a crouch tutorial

    • @SpeedTutor
      @SpeedTutor  3 дня назад +1

      I didnt but it's something I could do! :)

  • @Gorila-el8yw
    @Gorila-el8yw 7 месяцев назад +1

    thank you you are the best

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

      You're very welcome! :)

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

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

    underrated

  • @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 :)

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

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

  • @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! :)

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

    🔥🔥🔥

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

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

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

      I'm not sure what you're asking?

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

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

  • @FONORX
    @FONORX 11 месяцев назад

    Landing sound after jumping... neeed

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

  • @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 :)

  • @ayon...
    @ayon... Год назад

    How do I create the sample scene

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

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

  • @benzeji
    @benzeji 11 месяцев назад

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

    • @SpeedTutor
      @SpeedTutor  11 месяцев назад

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

    • @benzeji
      @benzeji 11 месяцев назад

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