UNITY 3D PLAYER MOVEMENT in 2 MINUTES! FPS Shooter

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น • 807

  • @Brogrammer1
    @Brogrammer1  ปีที่แล้ว +406

    Here is the script. If you are confused please let me know!
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    [RequireComponent(typeof(CharacterController))]
    public class PlayerMovement : MonoBehaviour
    {
    public Camera playerCamera;
    public float walkSpeed = 6f;
    public float runSpeed = 12f;
    public float jumpPower = 7f;
    public float gravity = 10f;
    public float lookSpeed = 2f;
    public float lookXLimit = 45f;
    public float defaultHeight = 2f;
    public float crouchHeight = 1f;
    public float crouchSpeed = 3f;
    private Vector3 moveDirection = Vector3.zero;
    private float rotationX = 0;
    private CharacterController characterController;
    private bool canMove = true;
    void Start()
    {
    characterController = GetComponent();
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    }
    void Update()
    {
    Vector3 forward = transform.TransformDirection(Vector3.forward);
    Vector3 right = transform.TransformDirection(Vector3.right);
    bool isRunning = Input.GetKey(KeyCode.LeftShift);
    float curSpeedX = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis("Vertical") : 0;
    float curSpeedY = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis("Horizontal") : 0;
    float movementDirectionY = moveDirection.y;
    moveDirection = (forward * curSpeedX) + (right * curSpeedY);
    if (Input.GetButton("Jump") && canMove && characterController.isGrounded)
    {
    moveDirection.y = jumpPower;
    }
    else
    {
    moveDirection.y = movementDirectionY;
    }
    if (!characterController.isGrounded)
    {
    moveDirection.y -= gravity * Time.deltaTime;
    }
    if (Input.GetKey(KeyCode.R) && canMove)
    {
    characterController.height = crouchHeight;
    walkSpeed = crouchSpeed;
    runSpeed = crouchSpeed;
    }
    else
    {
    characterController.height = defaultHeight;
    walkSpeed = 6f;
    runSpeed = 12f;
    }
    characterController.Move(moveDirection * Time.deltaTime);
    if (canMove)
    {
    rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
    rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
    playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
    transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
    }
    }
    }

  • @hepona6073
    @hepona6073 10 หลายเดือนก่อน +5

    bro you are my hero. i have been stuck at the player movement for 4 years but finally i found a working tutorial. i love you so much

    • @Brogrammer1
      @Brogrammer1  10 หลายเดือนก่อน

      No problem!

  • @oryxdotpng
    @oryxdotpng 9 หลายเดือนก่อน +35

    This is the best coding tutorial I have gotten so far. When I first tried Unity, I was unable to comprehend the game engine and quit. Now, a few months later, I have a working 3D project. Thank you. So much.

    • @Brogrammer1
      @Brogrammer1  9 หลายเดือนก่อน +2

      You're very welcome!

    • @MuhammadDaudJan
      @MuhammadDaudJan 5 หลายเดือนก่อน +3

      @@Brogrammer1 Make an explanation video

  • @Redblocks_14
    @Redblocks_14 8 หลายเดือนก่อน +4

    I would like A kind of detailed tutorial that shows you how to like change the speed and jump height I like something like that

    • @pengloalt5
      @pengloalt5 2 หลายเดือนก่อน +2

      just change them in the script

    • @insta_fn
      @insta_fn 2 หลายเดือนก่อน

      @@pengloalt5 fr
      also @pengloalt5 its nice to see some people stilll coding and watching this channel

  • @Unk00s
    @Unk00s 9 วันที่ผ่านมา

    finally no garbage tutorial 2h long where I will forget stuff 3 seconds after doing them. straight to the point. thanks :D

  • @acceleratingthesupernatural
    @acceleratingthesupernatural ปีที่แล้ว +31

    Bro I fucking love you. I had spent half an hour battling with like 3 scripts for the alternative input manager from unity until I decided to scrap the entire movement system and look for another solution. Yours worked like a charm, you are a legend man

    • @beefytime1374
      @beefytime1374 11 หลายเดือนก่อน +5

      Same

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +10

      Glad I could help :)

  • @RedX3010
    @RedX3010 หลายเดือนก่อน +5

    Issue:
    -Player falls through the ground even with colliders (on plain / terrain; and on player model)
    Fix:
    - If you create a player folder as in the video, you must nest the camera under the player model
    I've also chatGPT'd the script. (Sorry, I suck at writing code, I learn by being shown examples)
    This version has a crouch transition (and moves it from "R" to Left Control (Bro wtf, why u crouch on R?)
    Also, it has some more fine tuning to make it feel more real (or closer to CS / Source Games)
    It also prevents the running speed to apply mid air; Cant run while crouched; Run Speed is maintained if you release shift mid air. (couldn't figure out to keep the momentum if you release any of the walk keys, sorry)
    Added a crouch speed option. Slow tbag / Fast tbag.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    [RequireComponent(typeof(CharacterController))]
    public class PlayerMovement : MonoBehaviour
    {
    public Camera playerCamera;
    public float walkSpeed = 3f;
    public float runSpeed = 6f;
    public float jumpPower = 7f;
    public float gravity = 20f;
    public float lookSpeed = 2f;
    public float lookXLimit = 90f;
    public float defaultHeight = 2f;
    public float crouchHeight = 1f;
    public float crouchSpeed = 3f;
    public float crouchTransitionSpeed = 15f; // Speed of crouch height transition
    private Vector3 moveDirection = Vector3.zero;
    private float rotationX = 0;
    private CharacterController characterController;
    private bool canMove = true;
    private bool isCurrentlyRunning = false; // Tracks running status
    private float targetHeight; // Target height for crouching/standing
    void Start()
    {
    characterController = GetComponent();
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    // Set initial height
    targetHeight = defaultHeight;
    }
    void Update()
    {
    Vector3 forward = transform.TransformDirection(Vector3.forward);
    Vector3 right = transform.TransformDirection(Vector3.right);
    // Determine if the player is grounded
    bool isGrounded = characterController.isGrounded;
    // Crouch logic (press and hold)
    if (Input.GetKey(KeyCode.LeftControl) && canMove)
    {
    targetHeight = crouchHeight;
    }
    else
    {
    targetHeight = defaultHeight;
    }
    // Smoothly adjust height
    characterController.height = Mathf.Lerp(characterController.height, targetHeight, crouchTransitionSpeed * Time.deltaTime);
    // Adjust speed while crouching
    bool isCrouching = Mathf.Abs(characterController.height - crouchHeight) < 0.1f;
    if (isCrouching)
    {
    isCurrentlyRunning = false; // Cannot run while crouching
    }
    // Determine movement speed
    if (Input.GetKey(KeyCode.LeftShift) && isGrounded && !isCrouching)
    {
    isCurrentlyRunning = true; // Start running if grounded and shift is held
    }
    else if (isGrounded)
    {
    isCurrentlyRunning = false; // Stop running if grounded and shift is not held
    }
    float currentSpeed = isCrouching ? crouchSpeed : (isCurrentlyRunning ? runSpeed : walkSpeed);
    float curSpeedX = canMove ? currentSpeed * Input.GetAxis("Vertical") : 0;
    float curSpeedY = canMove ? currentSpeed * Input.GetAxis("Horizontal") : 0;
    // Preserve Y-axis movement
    float movementDirectionY = moveDirection.y;
    if (isGrounded)
    {
    // Update movement direction when grounded
    moveDirection = (forward * curSpeedX) + (right * curSpeedY);
    }
    else
    {
    // Maintain momentum while airborne
    Vector3 horizontalVelocity = new Vector3(moveDirection.x, 0, moveDirection.z);
    Vector3 inputVelocity = (forward * curSpeedX) + (right * curSpeedY);
    // Add input to current horizontal velocity
    if (inputVelocity != Vector3.zero)
    {
    horizontalVelocity = inputVelocity;
    }
    moveDirection = horizontalVelocity;
    }
    // Apply Y-axis movement
    moveDirection.y = movementDirectionY;
    // Jump logic
    if (Input.GetButton("Jump") && canMove && isGrounded)
    {
    moveDirection.y = jumpPower;
    }
    // Apply gravity if not grounded
    if (!isGrounded)
    {
    moveDirection.y -= gravity * Time.deltaTime;
    }
    // Move the character
    characterController.Move(moveDirection * Time.deltaTime);
    // Handle camera rotation
    if (canMove)
    {
    rotationX += -Input.GetAxis("Mouse Y") * lookSpeed;
    rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
    playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
    transform.rotation *= Quaternion.Euler(0, Input.GetAxis("Mouse X") * lookSpeed, 0);
    }
    }
    }

    • @BS.PTASIO
      @BS.PTASIO 19 วันที่ผ่านมา

      hey i did it and its not fixed. what can i do?

    • @SelketRuaThePirate
      @SelketRuaThePirate 10 วันที่ผ่านมา +1

      THANK YOU BRO IM GIFTING U A SUB DUDE THANK YOU!!! THIS HELPED ALOT❤❤

  • @BananaPuddingMuntjac
    @BananaPuddingMuntjac ปีที่แล้ว +19

    This was really helpful, I couldn’t find a tutorial that I actually understood until now

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +7

      Glad I could help

    • @Ossmania
      @Ossmania 10 หลายเดือนก่อน +2

      @@Brogrammer1 You earned a sub Thanks

    • @GKBGAMER9733
      @GKBGAMER9733 9 หลายเดือนก่อน +1

      It doesn’t work 😢

    • @Ossmania
      @Ossmania 9 หลายเดือนก่อน

      @@GKBGAMER9733 It does

    • @gilmannguyen9434
      @gilmannguyen9434 9 หลายเดือนก่อน +4

      if we just copy the code, that not mean we understand it
      ...

  • @Yassinji
    @Yassinji 2 หลายเดือนก่อน

    I tried for SOOO Long to look for a good Tutorial, YOU ARE THE GOAT THANKS MAN!!!!

  • @Laggyboiii
    @Laggyboiii ปีที่แล้ว +2

    hey, i wanted to thank you. i needed this for a schoolproject i need to finish next week. thanks

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +1

      A bit late, but im glad I could help :)

  • @kutlutortop4245
    @kutlutortop4245 ปีที่แล้ว +6

    holyyyyy this is the tutorial that was the easiest to understand. also thank you so much for posting the code in the comments, I don't have to pause the video every 10 seconds to write the code and waste time. Instead i can look through it myself after it is in a working state.

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      I like to make my videos as easy as possible to follow :) glad I could help

  • @ReedFootball
    @ReedFootball ปีที่แล้ว +11

    I HAVE BEEN SEARCHING THROUGH SO MANY TUTORIALS AND UR IS THE FIRST TO ACTUALLY WOKR!!!!!!

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      I'm glad to hear it worked :)

  • @q-in9up
    @q-in9up หลายเดือนก่อน

    GOD BLESS YOU!!!!! I SPENT 5 HOURS TRYING TO DO IT N HERE YOU ARE DOING IT IN 2 MINUTES

  • @paytonwhite2491
    @paytonwhite2491 หลายเดือนก่อน

    Thanks man! This saved me a good amount of time as a beginner game designer. Much appreciated.

  • @Lux11-XMP
    @Lux11-XMP หลายเดือนก่อน

    I will literally make out with you u finally helped all the ppl who needed this perfect script without any fking errors I've been struggling with other scripts for days and your's work. Thank you so much!

  • @christophergamer626
    @christophergamer626 8 หลายเดือนก่อน +4

    for some reason i have a bug, my player is moving without control, if you make a vid of how to fix that than you will get 10 subs (because i have this and other 9 devices)

  • @TheCraft100
    @TheCraft100 ปีที่แล้ว +2

    Bro Your A Frickin LIFESAVER man, THANKS

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      No Problem!

  • @fireblaze5260
    @fireblaze5260 8 หลายเดือนก่อน +2

    bro thank you so much i wouldve never been able to do anything ever and wouldve deleted unity immediately if i didnt have this

  • @cammyposey5054
    @cammyposey5054 8 หลายเดือนก่อน +9

    If your player is falling then click the player folder and a green line will show up. Click the capsule and move it up to the green line and it should work!

    • @travel2120
      @travel2120 2 หลายเดือนก่อน +2

      It works, to explain further it can be fixed under the "transform" component by setting the "camera" and "player" component to 0 on all the axes and when you want to move the player you should move the player folder because the items in the folder are relative to the player folders position

  • @stuff62720
    @stuff62720 ปีที่แล้ว +21

    Hay I know you posted this 2 months ago but I’m having a bit of trouble because when I add the script as a component it doesn’t add the character controller and the script shows but has no variables like “Camera” and “walk speed” it only has the name of the script.

    • @howtodie_1
      @howtodie_1 ปีที่แล้ว +1

      same

    • @MaxwellSpookyzLol
      @MaxwellSpookyzLol ปีที่แล้ว

      Same

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      Sorry for the super late reply - Make sure the name of the script is the exact same as the one I used in the video. That could be the issue.

    • @Chris-Stikman
      @Chris-Stikman 10 หลายเดือนก่อน

      Ok because I’m having the same issue

    • @stuff62720
      @stuff62720 10 หลายเดือนก่อน

      @@Chris-Stikman I fixed the issue, you kinda just have to re-save the script until it works

  • @I.m.trigno
    @I.m.trigno 3 หลายเดือนก่อน +1

    Thanks bro finally after 2 days I got a perfect tutorial love from india🇮🇳🇮🇳🇮🇳

  • @spaghettiHell
    @spaghettiHell 7 หลายเดือนก่อน +1

    I love you, you are the best, YOU PUT THE SCRIPT DOWN, THE SCRIPT WORKS PERFECTLY, YOU SOLVED A 5 HOUR LONG PROBLEM IN SECONDS, YOU NEED ALL THE SUBS

  • @BlipBlobFishman
    @BlipBlobFishman 21 วันที่ผ่านมา

    Bro absolute best tutorial i've ever used!

  • @igimsalami
    @igimsalami 9 หลายเดือนก่อน

    ur such a W bro, ive been looking for wasd controls since like, january, and this one finally worked, and i didnt expect it to only take 2 minutes, (i know it wouldve taken way longer if you didnt just let us copy the code, and instead walked us through the code like others)

  • @danielandhenry1082
    @danielandhenry1082 3 หลายเดือนก่อน

    i have been using this tutorial for like a year and it still works thank you!!!

    • @TeamWithCake-jn9qp
      @TeamWithCake-jn9qp 3 หลายเดือนก่อน

      bro how? i used it and it says assets\PlayerMovement\.cs(97,6):error CS1002 : ; expected

  • @THE_KID_CLOPPY
    @THE_KID_CLOPPY หลายเดือนก่อน

    best tutorial i have ever seen thanks very much bro
    i subed and liked

  • @Zack-c3z
    @Zack-c3z 2 หลายเดือนก่อน

    Thank you!, One of the best controllers i've seen so far the others are either inverted controlls or just fall over

  • @RealGhsty
    @RealGhsty 2 หลายเดือนก่อน

    Learning the basics and watched many videos and this worked perfectly thank you!!

  • @Random99993
    @Random99993 ปีที่แล้ว

    First totorial that works. Thank you

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      No Problem!

  • @benoOnDiddy
    @benoOnDiddy 2 หลายเดือนก่อน

    Thank You so much this showed exactly what to do. You earned a sub!

  • @average_guy319
    @average_guy319 3 หลายเดือนก่อน

    Bro I tried to like make this by myself but for some reason my dumb ahh brain could not because I tried rigidbody which made the movement super unnatural but with your script, and character controller, it is very effective and super natural movement. Thanks bro and you just earned a free sub and a like.

  • @NicestAngel
    @NicestAngel 6 หลายเดือนก่อน +1

    EEK!! THANK YOU SO MUCH BRO, I LOVE YOU!! (not in a weird way)

  • @Nave-v9f
    @Nave-v9f 2 หลายเดือนก่อน

    Thank you so much, I am just getting started with unity and this tutorial is helping me create my dream game!!!!

  • @David64580
    @David64580 11 หลายเดือนก่อน +2

    THANK U SO MUCH MAN THIS IS MY LIKE 20TH TUTORIAL THAT I TRIED AND IT FINALLY WORKS THANKS

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Haha, glad I could help!

  • @landonhampton3799
    @landonhampton3799 5 หลายเดือนก่อน

    Thanks for this! Worked completely fine.

  • @diamondarmorkid8220
    @diamondarmorkid8220 2 หลายเดือนก่อน +2

    does not work when I put the script on the player it does not show any thing to attach my camera too

  • @gaming_with_Jordy1504
    @gaming_with_Jordy1504 2 หลายเดือนก่อน

    Damn, third time realy is the charm, tried 2 before, both failed, and now i see a realy simple fast tutorial, and it works like a charm

  • @UnleasedRL
    @UnleasedRL ปีที่แล้ว +1

    Thanks for the help because I'm new to unity :)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      You're welcome :)

  • @themrinigo8686
    @themrinigo8686 ปีที่แล้ว

    thank you, Ive been serching for hours how to make my player move and youre tutorial was the only on that worked, thank you

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad I could help!

  • @KevinKolack
    @KevinKolack ปีที่แล้ว +1

    Thanks! So many tutorials but this one was the best!

  • @GoldenRabbitsDiner
    @GoldenRabbitsDiner 2 หลายเดือนก่อน

    Thank you so much! This worked amazing and helped a lot!

  • @ccpbg
    @ccpbg 5 หลายเดือนก่อน +1

    Bro thanks so much I watched a lot of other videos and I made it for so long but it didn’t even work but thanks to you you even put the script in the commans

  • @PandexOnYT
    @PandexOnYT 6 หลายเดือนก่อน

    this is the PERFECT Tutorial its short and everything works perfect this is the first game i ever make and im so happy thx a lot

  • @2_or3
    @2_or3 11 หลายเดือนก่อน

    hippity hoppity, this code is my property (this tut actually helped a lot thanks mate)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      No problem :)

  • @ikerpaezrodriguez9735
    @ikerpaezrodriguez9735 4 หลายเดือนก่อน

    Finally a tutorial that works i love you bro keep up the good work.

  • @beefytime1374
    @beefytime1374 ปีที่แล้ว +1

    Easiest and fastest fps view game controller thankyou so much.

  • @Redblocks_14
    @Redblocks_14 8 หลายเดือนก่อน +3

    This is a really good video it helped me

  • @Washed_Primus
    @Washed_Primus หลายเดือนก่อน

    this was actually helpful thanks

  • @Streed-vy4sh
    @Streed-vy4sh 11 หลายเดือนก่อน +1

    bro thank you so much this really helped me

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad it helped

  • @DeApple_king
    @DeApple_king 10 หลายเดือนก่อน

    I loved the video and it really helped me a lot! Thanks!

    • @Brogrammer1
      @Brogrammer1  10 หลายเดือนก่อน

      Glad it helped!

  • @bot_matrix
    @bot_matrix หลายเดือนก่อน

    I might be wrong but the walk speed doesn't seem to be set correctly. You are setting the walk speed to the crouch speed when the crouch button is selected, else you are setting the walk speed to 6f directly. So while the variable is technically public, it is set automatically by that function. A solution I found was to create an "originalWalkSpeed" variable that is set the same as walk speed. So instead of saying walkSpeed = 6f, you would say walkSpeed = originalWalkSpeed;.
    Keep in mind that I removed the sprint functionality so it could have been a result of that, but I don't think so.

  • @hannahgreen9881
    @hannahgreen9881 6 หลายเดือนก่อน

    Thanks so much for script, you just write my 1st script

  • @MemoryYT11
    @MemoryYT11 5 หลายเดือนก่อน +1

    I would suggest putting a collider on the camera so that you do not see through things

  • @Jakub_gaming25
    @Jakub_gaming25 2 หลายเดือนก่อน +1

    Can someone pls help when ever i try to drag the script into the conponent box it says the file name and class name dont match

  • @Bashi_boi
    @Bashi_boi 11 หลายเดือนก่อน

    Really great tutorial! I can finaly start making stuff!

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Great to hear!

  • @Frogo333
    @Frogo333 ปีที่แล้ว

    bro thanks so much it works perfectly and it is sick and easy bro keep the good work up

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Happy to hear it works :)

  • @Ruarc1
    @Ruarc1 9 หลายเดือนก่อน +2

    Can you please help me ive been trying for ages and ive restarted the project loads of times but nothing works. At 1:40 when i drag and srop it there is no option for the player camrea and its just all greyed out please help ive looked at multiple videos but its just the same issue.

    • @Ruarc1
      @Ruarc1 9 หลายเดือนก่อน

      nvm i got it working

    • @s6ombie
      @s6ombie 9 หลายเดือนก่อน

      @@Ruarc1how did you fix it

    • @Hydrix_1
      @Hydrix_1 9 หลายเดือนก่อน

      @@Ruarc1 thats happening to me how did you fix it?

    • @jadenhefner5049
      @jadenhefner5049 7 หลายเดือนก่อน

      @@Hydrix_1 me too its so annoying

    • @ThatGuy_3079
      @ThatGuy_3079 4 หลายเดือนก่อน

      How did you fix it I'm having the same problem

  • @OfficialKaiVerse
    @OfficialKaiVerse ปีที่แล้ว +1

    Very good Tutorial easy to setup so customizable I subscribed btw :)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      Thanks for the sub! I'm glad it works

  • @LouieNegrijn
    @LouieNegrijn 4 หลายเดือนก่อน

    Thank you so Fuuuuging much bro easies tuturial ever

  • @TxY01V_
    @TxY01V_ 7 หลายเดือนก่อน

    Thank u very much for this great tutorial :D

  • @keicoscomedy
    @keicoscomedy 6 หลายเดือนก่อน

    Thank you so much! Worked like a charm!

  • @Xxyrow
    @Xxyrow 11 หลายเดือนก่อน

    thank you this was super useful :)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad it was helpful!

  • @keyxedia
    @keyxedia 6 หลายเดือนก่อน

    thank you brother i was struggling tryna learn the code but u made it so easy great to help me study and referance off of big thanks

  • @BestEraUA
    @BestEraUA ปีที่แล้ว +1

    Thats literally the best video tutorial about fps control

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad you liked it :) More videos coming up as well

  • @Plush_captain_
    @Plush_captain_ 3 วันที่ผ่านมา

    It says it can’t add the script but that’s probably because I’m on the wrong version of unity

  • @Redblocks_14
    @Redblocks_14 8 หลายเดือนก่อน +59

    Everything worked fine except the fact that My character decided just not to obey the laws of physics and follow through the ground so EDIT THANK YOU FOR 38 LIKES

    • @kunal-ko
      @kunal-ko 8 หลายเดือนก่อน +7

      Add a rigidbody component to it. Should work fine

    • @fardplayer69
      @fardplayer69 8 หลายเดือนก่อน

      Cause you didn't add a capsule collider to it or maybe you didn't add a collider to your ground

    • @QuaninVN
      @QuaninVN 7 หลายเดือนก่อน

      Fr

    • @UrPlagued-hd5tr
      @UrPlagued-hd5tr 6 หลายเดือนก่อน

      😂

    • @Xurg56
      @Xurg56 4 หลายเดือนก่อน

      Mine some reason floats

  • @linusasbjrnsimonlautruplyn4537
    @linusasbjrnsimonlautruplyn4537 ปีที่แล้ว +2

    For me it falls through the terrain even tho i have colliders for both they are not trigger (Fixed it i deleted the empty gameobject called player then i added the script to my player (game object)) (Fixed it)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad it hear its working now 👍

  • @Super_rock232
    @Super_rock232 หลายเดือนก่อน

    uh everytime i try to drag the player movement script into the player 1:40 it writes this:
    Can't add script behaviour 'PlayerMovement'. The script needs to derive from MonoBehaviour!
    pls help

  • @Axalote
    @Axalote 12 วันที่ผ่านมา

    Can't add script behaviour 'PlayerMovement'. The script needs to derive from MonoBehaviour!

  • @SuperAdonisGaming
    @SuperAdonisGaming 8 หลายเดือนก่อน +2

    I tried third person but the camera keeps on turning around when i start up the game and wont follow the player

    • @HaiderSaqib-id4ry
      @HaiderSaqib-id4ry 7 หลายเดือนก่อน

      hmm try to make another script with camera movement and delete the camera movement from the movement script and like just make a new one or search up a new script

  • @mr.manTF2
    @mr.manTF2 หลายเดือนก่อน

    thanks for not putting a 1 minute intro, 2 minute explanation on what the script does, 1 minute of trying to fix a bug in the script, and 5 minutes of blabbering but instead just going into the video instantly

  • @wakeup717
    @wakeup717 23 วันที่ผ่านมา

    the camera didnt follow the player model and when i look around it looks at the middle of something; basically when i look around it moves my player in a giant circle

  • @Beast-Studios-m1b
    @Beast-Studios-m1b 5 หลายเดือนก่อน +4

    can someone help my floor keeps falling into the void and i can't find a tutorial to fix it i only started unity yesterday and if u can help the will me appreciated

    • @CHICKEN_sandwich_from_ohio
      @CHICKEN_sandwich_from_ohio 4 หลายเดือนก่อน +1

      I think that the floor doesn’t have collision

    • @CHICKEN_sandwich_from_ohio
      @CHICKEN_sandwich_from_ohio 4 หลายเดือนก่อน +1

      Idk how to add collision i just got unity today

    • @sklavar
      @sklavar 4 หลายเดือนก่อน +1

      add mesh collider to floor

  • @ShxdowsMusics
    @ShxdowsMusics 8 หลายเดือนก่อน +1

    you are a LIFE SAVER!!! i was so confused since i dont know c#, thank you a lot!

  • @Da_best_in_za_west
    @Da_best_in_za_west 8 หลายเดือนก่อน

    Bro im totally new to unity and this tutorial will help me with alot of games

  • @7N8173
    @7N8173 หลายเดือนก่อน

    Can't add script component 'PlayerMovement' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.

  • @fugey1701
    @fugey1701 ปีที่แล้ว +1

    it did work but For me I was not impressed I started to have problem like the camera not sticking to the player and even with colliders for my ground it still falls thought but kinda helpfull

  • @neringaposkyte937
    @neringaposkyte937 16 วันที่ผ่านมา

    why does it only permit monobehaviour scripts?i cant add the script component on empty c script,i cant even make games with that,what did unity did dude...

  • @Redblocks_14
    @Redblocks_14 8 หลายเดือนก่อน +2

    Hey I'm a bit confused here I made an entire character model inside of unity And Do I have to scrap it for the Capsule or can I use this

    • @Bitbybrix
      @Bitbybrix 6 หลายเดือนก่อน +1

      the capsule is simply a placeholder

  • @BLUE_MUSIC777
    @BLUE_MUSIC777 3 หลายเดือนก่อน

    Thanks for pinning the script in comments❤❤

  • @Pigga_Prime
    @Pigga_Prime ปีที่แล้ว +6

    not only did this man make a 2 min tutorial straight to the point, but even put the script in the comments. Absolute chad. Keep up the great work. However im having a small problem. When i change the values of the Run speed & walk speed and then start the game the run speed resets to 12 and the walk speed resets to 6. How can i fix this?

    • @fritzwulf
      @fritzwulf ปีที่แล้ว

      Did you make sure that you edited the values with the play button unselected? If you change anything while in play mode (even if you also have it paused) it will reset.

    • @eclair25
      @eclair25 11 หลายเดือนก่อน

      Edit the code on lines 67 and 68. It says that if you are not crouching or sprinting, it will set these values ​​to 6 and 12

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +1

      Sorry for the late reply, instead of through unity, try changing the values through the actual script. Just look for where I have the walk and run speed set and change the values there. You can use control f to search for keywords.

  • @AviyaleTales
    @AviyaleTales ปีที่แล้ว +9

    Hey thank you! I used your code for my game to make snappy movement and its perfectly scalable and clean! I have some big ideas and needed a good movement base to work off of so thank you so much

  • @agentsimon
    @agentsimon 2 หลายเดือนก่อน

    Great..finally I got it to work..thanks

  • @taku_and_jesus
    @taku_and_jesus 6 หลายเดือนก่อน

    Thanks man this was a lot of help❤

  • @zerg6205
    @zerg6205 9 หลายเดือนก่อน +1

    VERY helpful and simple! Thank You for nailing this tutorial!

  • @Michele11TCG
    @Michele11TCG 6 หลายเดือนก่อน

    First of all, THANK YOU SO MUCH. Besides this, could you please create more videos similar to this one? It's helped me a lot, and it would be great if you could help with other things as well

  • @alvaroromancasariego4908
    @alvaroromancasariego4908 ปีที่แล้ว

    FINALLY, THANK YOU MAN YOU SAVED MY LIFE

  • @TMP5_xd
    @TMP5_xd 10 หลายเดือนก่อน +2

    I've got a question, though I'm not sure if you'll answer given this is a 9 month old tutorial. The movement works overall, but I find that when moving diagonally the speed is increased. Do you have any idea on how to fix this?

    • @gokete3555
      @gokete3555 10 หลายเดือนก่อน

      don't fix it, it's a really known thing on movement systems, games like minecraft and karlson have it. it is not uncommon at all

    • @TMP5_xd
      @TMP5_xd 10 หลายเดือนก่อน

      @@gokete3555 Thing is, i don’t really want that in my game

    • @Dylanj8795
      @Dylanj8795 10 หลายเดือนก่อน

      @@TMP5_xd no one will notice that

    • @TMP5_xd
      @TMP5_xd 10 หลายเดือนก่อน

      @@Dylanj8795 They almost certainly will

    • @Dylanj8795
      @Dylanj8795 10 หลายเดือนก่อน

      @@TMP5_xd I have been playing games for a really long time now and I have never noticed that so….

  • @PureM4gicStudios
    @PureM4gicStudios ปีที่แล้ว

    Finally i don't have to sit here for 30 miinutes to make movement. Chad

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      No wasted time here👌

  • @codewithakthar-wc2nn
    @codewithakthar-wc2nn ปีที่แล้ว

    Great Brother ! .i was Looking For the Perfect Movement Script ,!

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Glad it works :)

  • @PersonalisedPetsLtd
    @PersonalisedPetsLtd ปีที่แล้ว +2

    i had 3 errors while adding your script and i dont know how to fix them pls could u tell me how to the errors were Assets/PlayerMovement.cs(23,10: error CS1529: A clause must precede all other elements defined in the namespace exept extern allies declarations

    • @PersonalisedPetsLtd
      @PersonalisedPetsLtd ปีที่แล้ว

      the other 2 were the same (errors)

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Ensure that the name of the file is the exact name I used in the video! Also copy the code directly from the comments and use that.

  • @narukirk
    @narukirk ปีที่แล้ว +1

    Thanks! This tutorial was really helpfull for my game.

  • @Renek2
    @Renek2 10 หลายเดือนก่อน

    when i play the game my bean player starts spinning around and then falls down

  • @piyush-editz61
    @piyush-editz61 ปีที่แล้ว +1

    op bro good job and pls make the video how to make AI enemies in your game in unity

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน +2

      Sorry for the late response. I will work on that video soon! I just upload a working gun, so that could get you started on your ai journey :)

    • @piyush-editz61
      @piyush-editz61 11 หลายเดือนก่อน +1

      @@Brogrammer1 thanks bro for the Gun tutorial its really helpful
      Support from India

  • @rendered_fox1234
    @rendered_fox1234 14 วันที่ผ่านมา

    my camera is sucessfully moving but my player character wont move an inch no matter what i do. anyone know the fix?

  • @muhittinkeser
    @muhittinkeser หลายเดือนก่อน

    actually, creating a folder named player causes some problems as the player is falling through the terrain. instead of doing that, do the same things without creating player folder. just a capsule and a main camera.

    • @matty_100
      @matty_100 23 วันที่ผ่านมา +1

      This worked for me. Thanks!

  • @Footbaltopic
    @Footbaltopic 11 หลายเดือนก่อน

    great video man 👍

    • @Brogrammer1
      @Brogrammer1  11 หลายเดือนก่อน

      Appreciate it!

  • @blobsgaming92
    @blobsgaming92 หลายเดือนก่อน

    When I double click on the script it asks me "How do you want to open this file" and I'm just wondering what file do I choose to open the script.

  • @monkefrrr
    @monkefrrr 6 หลายเดือนก่อน

    Bro thank you, you helped so much!!!!

  • @aymeric-devv
    @aymeric-devv 2 หลายเดือนก่อน

    Thank you very much it work really good for my