THIRD PERSON MOVEMENT in Unity

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

ความคิดเห็น • 3K

  • @Chiu-Pin
    @Chiu-Pin 2 ปีที่แล้ว +138

    Book Mark
    2:06 Start (The course sounds great!)
    4:38 Free Look Camera
    17:37 Camera clip

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

      When I hit Play , camera snaps to different position,(in front upward of the player)
      (It is working fine after that ,when I move mouse it moves the camera accordingly , but snap at starting the game is weird)
      (I have tried locking the cursor in start , but still snap problem exist)
      Why is this Happening , Please Help...

    • @TheSkeleton27
      @TheSkeleton27 2 ปีที่แล้ว

      Thanks mate

    • @joecraft9098
      @joecraft9098 2 ปีที่แล้ว

      69 likes...
      *Nice*

  • @michaelanderson2861
    @michaelanderson2861 3 ปีที่แล้ว +801

    Bless your soul Brackeys! I miss you evey day

    • @rein556
      @rein556 3 ปีที่แล้ว +26

      Gave us so much information to us without expecting anything from us

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

      @@rein556 ahah good one

    • @rein556
      @rein556 3 ปีที่แล้ว +18

      @@melomaniakjm no I am serious,He really gave us so many tutorials for free

    • @kartavyaseth6582
      @kartavyaseth6582 3 ปีที่แล้ว +22

      He is not dead 🤣 he only quit youtube

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

      @@kartavyaseth6582 lol 😂😂😂😂🤣😹🤣

  • @Phoenix-0455
    @Phoenix-0455 3 ปีที่แล้ว +531

    To lock the cursor, use the line 'Cursor.lockState = CursorLockMode.Locked;' in the start function.

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

      thanks

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

      Thats really helpful thank youuuu

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

      @@WZDRIP And thank you for replying, otherwise i would've scrolled past this comment

    • @just-some-guy-without-a-mo9702
      @just-some-guy-without-a-mo9702 3 ปีที่แล้ว +1

      I wouldn’t understand anyways, I don’t even have Visual Studio and don’t know how to open my Third Person Controller script on it...

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

      @@just-some-guy-without-a-mo9702 😮😮😮

  • @Demon.Immortalis
    @Demon.Immortalis 3 ปีที่แล้ว +122

    tip: if u dont want ur camera to move up and down(y-axis) go to y axis in cinemachine and set the speed to 0 :). hope it helps!

    • @bst-music6517
      @bst-music6517 2 ปีที่แล้ว +3

      Kinda obvious but thanks anyways

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

      @@bst-music6517 Not rly. I'm a beginner and I really would've struggled around for a bit without this comment lmao.

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

      Thank youuuu I think I will need that

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

      @@bst-music6517 there's always one...

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

      The character won't turn with my camera, after I copied the top comment's code, can you help?

  • @Morphinias
    @Morphinias 4 ปีที่แล้ว +3144

    I can already see my brand new unfinished project
    Edit:
    I did not expect a 1000+ likes. Wow!

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

      That is exactily what i was thinking at

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

      Yeah! Lol 😂😂

    • @dgameboss4963
      @dgameboss4963 4 ปีที่แล้ว +8

      th-cam.com/video/Yf9f8eC-Jdk/w-d-xo.html
      Hey there it's me again DGame_Boss and this time I took a challenge too make a complete Game in 24hrs and the game is a replica of a popular mobile game call ball blast...
      My apologies for spamming you this way...
      Enjoy the video and have a nice day.
      😁

    • @Futureblur
      @Futureblur 4 ปีที่แล้ว +5

      Underrated :)

    • @aludjahjerod8678
      @aludjahjerod8678 4 ปีที่แล้ว +3

      100%😂😂

  • @robotman5105
    @robotman5105 4 ปีที่แล้ว +170

    I'm extremely appreciative of the fact that he made the code with the intention of being open for customization instead of being specific and restrictive. Literally a perfect video for a basic third person controller.

    • @Wonder_Verse_Tech
      @Wonder_Verse_Tech 2 ปีที่แล้ว

      When I hit Play , camera snaps to different position,(in front upward of the player)
      (It is working fine after that ,when I move mouse it moves the camera accordingly , but snap at starting the game is weird)
      (I have tried locking the cursor in start , but still snap problem exist)
      Why is this Happening , Please Help...

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

      @How to Yes I thought when I normally comment on TH-cam channel, only channel admin will get the notification and other devs will help me when see my comment, I replied in few of the comments such that they will be get notified and may help me regarding this .

    • @Kasuga-
      @Kasuga- 2 ปีที่แล้ว

      @@Wonder_Verse_Tech did u put the player game object accordingly? 5:16

  • @SpaceflightRocketShorts
    @SpaceflightRocketShorts 3 ปีที่แล้ว +557

    I was able to watch this video 14 times while waiting for Unity to load...

    • @SpaceflightRocketShorts
      @SpaceflightRocketShorts 3 ปีที่แล้ว +3

      @@taj2163 good question I also made a comment for that and I never got a good response

    • @nerbea1
      @nerbea1 3 ปีที่แล้ว +10

      so you were waiting 5 hours! i feel really bad...

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

      2 gb ram lol

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

      so sorry for your loss

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

      (X) Same

  • @aaronkanaron
    @aaronkanaron 4 ปีที่แล้ว +863

    If anyone is too lazy to write the code themselves, or just don't know how to do it; Here is my script which includes gravity, jumping, and everything shown in this video. You can also tweak it however fits your game :D
    (Press read more)
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Security.Cryptography;
    using System.Threading;
    using UnityEngine;
    public class ThirdPersonMovement : MonoBehaviour
    {
    public CharacterController controller;
    public Transform cam;
    public float speed = 6;
    public float gravity = -9.81f;
    public float jumpHeight = 3;
    Vector3 velocity;
    bool isGrounded;
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;
    float turnSmoothVelocity;
    public float turnSmoothTime = 0.1f;
    // Update is called once per frame
    void Update()
    {
    //jump
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
    if (isGrounded && velocity.y < 0)
    {
    velocity.y = -2f;
    }
    if (Input.GetButtonDown("Jump") && isGrounded)
    {
    velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
    }
    //gravity
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);
    //walk
    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
    if(direction.magnitude >= 0.1f)
    {
    float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
    transform.rotation = Quaternion.Euler(0f, angle, 0f);
    Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
    controller.Move(moveDir.normalized * speed * Time.deltaTime);
    }
    }
    }

    • @AndenPMS
      @AndenPMS 4 ปีที่แล้ว +59

      God bless you, just tired of trying to learn C# for the past month lol

    • @nagybalint1474
      @nagybalint1474 4 ปีที่แล้ว +12

      thx i accidentally deleted the wrong script

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

      any idea how to trigger animations? I mean I tried to check velocity.x velocity.z but no and if I test if speed is 6 then it is so I need to have speed on 0 and if I hold a button it goes up to 6 or is there any better solution

    • @benjioffdsv
      @benjioffdsv 4 ปีที่แล้ว +13

      Why do you keep System.collections, system.threading and system.security ? These are useless for the script.

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

      Thank you, this was extremely helpful

  • @masterbuildertristan2494
    @masterbuildertristan2494 3 ปีที่แล้ว +35

    If any of you are using the High Definition template made by unity, and when testing game you may come along a message in the games window, try adding in the HD aditional camera data component.

  • @Sylfa
    @Sylfa 4 ปีที่แล้ว +23

    Please note, changing the camera near clip plane can really create a lot of Z fighting in the distance, or if you go to very extreme numbers, even in the middle distance.
    The reason is how floating points and the Z-buffer works, the Z-buffer stores the pixel depth as a number between 0 and 1, with a bias towards the numbers near the camera (it's non-linear, so 0.1 is not 10% through the distance between near and far clip, but much closer to the camera). And then ofc, the floating point can only store a certain amount of precision, you don't have infinite memory to write down all the decimal points after all.
    Practically this means that most of the Z-buffer is reserved for close to the camera, and by making the near value very small you basically make it so the difference between 100f and 101f is 0f, meaning objects far enough away will start occupying the same distance as far as the Z-buffer is considered.
    In general you want your near clip plane to be the highest you can tolerate in the game, and if you reduce it with an order of magnitude you *should* reduce the far clip with the same magnitude. So from 0.3 - 1000 to 0.03 - 100.
    Though I noticed now that Unity actually prevents you from going under 0.01 as near clip plane to avoid people setting it to 1e-10 and having everything just go wrong. Though you can set the far distance higher to see the effect partially, the near clip plane is more sensitive though due to the non-linear math being used.

  • @SpaceflightRocketShorts
    @SpaceflightRocketShorts 3 ปีที่แล้ว +444

    Me: making a race car game
    Brackeys: *we can think of the character controller as the motor that drives the player*
    Me: perfect.

    • @flaze2275
      @flaze2275 3 ปีที่แล้ว +13

      quality comment 👍

    • @2ksnakenoodles
      @2ksnakenoodles 3 ปีที่แล้ว +1

      Use WheelColliders

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

      perfect

    • @Dad3.9
      @Dad3.9 2 ปีที่แล้ว

      Perfection

    • @Corbano
      @Corbano 2 ปีที่แล้ว

      no

  • @laurenwilkerson2435
    @laurenwilkerson2435 3 ปีที่แล้ว +127

    Fyi in Unity 2019.4 "All Packages" has been Renamed to "Unity Registry"

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

      Thank you.

    • @rensalazar
      @rensalazar 3 ปีที่แล้ว

      Good to know. (no sarcasm) Thanks, sis!

    • @toniloncar1134
      @toniloncar1134 3 ปีที่แล้ว

      god bless you

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

      it dosnt work :(

  • @lucasbonde2
    @lucasbonde2 4 ปีที่แล้ว +23

    As always, so much quality in the videos! Never gets boring to learn from the Brackeys team!

  • @CP_Maverick
    @CP_Maverick 4 ปีที่แล้ว +22

    This came out at the perfect time. Had the idea for a third person shooter about three weeks ago, struggled to find code that I could easily add functionality on top of, and then I found this video. I've been coming back to it ever since then! Thank you!

    • @Shalashaska-x5x
      @Shalashaska-x5x 3 ปีที่แล้ว

      are you still learning game development?

    • @CP_Maverick
      @CP_Maverick 3 ปีที่แล้ว

      @@Shalashaska-x5x Every so often I come back to it, but I think I'm just more of an artist rather than a programmer xD

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

      Still foing game development ?

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

      @@AdeelNasir121 Not as much as I should. Ideas keep coming, but the time to properly develop them into vertical slices is never there like I want it to be. I imagine that's the typical struggle for most solo indie devs xD

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

    For anyone looking for the Cinemachine dropdown menu, it is now accessed by right-clicking in the Hierarchy tab. If you do this and Cinemachine is not present down the bottom, try right-clicking inside your Project tab and clicking Reimport All.

    • @MEATMANUNCHAINED
      @MEATMANUNCHAINED 2 ปีที่แล้ว

      thanks man, really helped me out

    • @brodymortensen1004
      @brodymortensen1004 2 ปีที่แล้ว

      for me i found cinemachine in the GameObject tab

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

      @@brodymortensen1004 That's because the GameObject tab is the same as the menu that appears when you right click in the Hierarchy tab.

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

      @@quoipi Oh my bad man! I'm still a little new too unity!

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

      @@SamTheTourists That's because the GameObject tab is the same as the menu that appears when you right click in the Hierarchy tab.

  • @andrewericliu3845
    @andrewericliu3845 4 ปีที่แล้ว +941

    Me : Works for hours writing camera collision code.
    Cinemachine: Does it in two clicks.
    Me: 0_0

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

      i can relate to this lol

    • @CristianCardosoMendesAntiMark
      @CristianCardosoMendesAntiMark 4 ปีที่แล้ว +27

      i did my script in seven hours, with a bad smoothing, i am really sad

    • @TotatoC
      @TotatoC 4 ปีที่แล้ว +7

      lmao same here

    • @rogerpatino3000
      @rogerpatino3000 4 ปีที่แล้ว +32

      I have the opposite problem. Before I implement ANYTHING, I obsessively look up resources online for hours to see if it has already done and I can just use someone else's method.

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

      It's literally what I was trying to get figured out the past couple days. then I look at this... Thank you!!

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

    I want to say thank you for making these videos! This quarantine made me realize I want to make my own game and your tutorials are my savior. If I end up really making it, I would tag you as my mentor!

  • @ikey07ch
    @ikey07ch 3 ปีที่แล้ว +12

    This was amazing tutorial, I really didnt wanted to use some 3rd person templates, as you never learn what exactly you have to do to achieve it, this was really helpful!

  • @butlerfuqua
    @butlerfuqua 4 ปีที่แล้ว +8

    This is fantastic! I don't think anyone has videos quite like yours. I love how you perfectly balance getting to the point and explaining what's going on. Please keep making videos like this!!!

    • @joe.lufc23
      @joe.lufc23 4 ปีที่แล้ว

      id dunt work do...

  • @zill4_
    @zill4_ 4 ปีที่แล้ว +22

    How would this work if you want gravity?
    [edit]x2 Below is my code, the main difference is that I am using a rigid body and gravity.
    Also to note that his rotation is always 'smoothing' so it never comes to rest, which is why I just use the just the target angle.
    translation = Input.GetAxisRaw("Vertical");
    straffe = Input.GetAxisRaw("Horizontal");
    vSpeed -= gravity * Time.deltaTime;
    movement = new Vector3(straffe, 0f, translation).normalized;
    if (controller.isGrounded)
    {
    // Jumping, if we are on the ground, v goes back to 0.
    vSpeed = 0;
    if (Input.GetKeyDown("space")){
    vSpeed = JumpForce;
    }
    }
    // movement rotation
    float targetAngle = Mathf.Atan2(movement.x, movement.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    transform.rotation = Quaternion.Euler(0f, targetAngle, 0f);
    // if vertical/horizontal are active isMove is True (1) else False (0)
    isMove = (( translation != 0 || straffe != 0) ? 1 : 0);
    // Direction for us to move given that motion is present (isMove)
    Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * (Vector3.forward * isMove);
    // Gravity acting on us.
    moveDir.y = vSpeed;
    // Movement
    controller.Move(moveDir.normalized * Speed * Time.deltaTime);

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

      what is cam.euler angles because unity says cam.euler angles out of context

    • @youtubestarter6664
      @youtubestarter6664 3 ปีที่แล้ว +3

      @@uv21 I think he forgot to copy the line "public Transform cam;" at the top so you get an error cause unity doesn't knwo what cam is (ps sry for my bad english)

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

      Could you send the entire code. I know its been a year but still I can use it..

    • @mateodemicheli2420
      @mateodemicheli2420 3 ปีที่แล้ว

      @@nachiketmore9068 Same here bro pls

    • @rayanesaada5080
      @rayanesaada5080 3 ปีที่แล้ว

      what is vSpeed?

  • @sam2chill
    @sam2chill 3 ปีที่แล้ว +12

    I’m glad to see people replying to people who need help, it shows how great a community Brackeys built sad to see him go

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

      wdym? am i the only person who doesnt know

    • @sam2chill
      @sam2chill 3 ปีที่แล้ว

      @@MeeMe3moOMoo what bro

    • @ghettosupastar9285
      @ghettosupastar9285 3 ปีที่แล้ว

      @@MeeMe3moOMoo Brackeys has quitted making new video's about Game Development in Unity. though he also implied that he might make a comeback nothing is set in stone. he is taking a break

  • @VerySus
    @VerySus 4 ปีที่แล้ว +418

    My brain started hurting when he started saying things like Euler and Quaternion...

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

      It’s just something y have to suffer through when your a dev

    • @PetersExcapades
      @PetersExcapades 4 ปีที่แล้ว +73

      ill try to explain it simply, think of Quaternion as a Vector3 with an extra value, or Vector4 for example, the quaternion has x, y, z, and w, it is really hard for us humans to visualize the w rotation, so we have Euler angles, if u do Quaternion.Euler(new Vector3(0, 90, 0)); this will create a quaternion that will turn ur character 90 degrees to the right (all rotation is clockwise). Euler() takes a vector3, transform.rotation uses Euler angles

    • @PetersExcapades
      @PetersExcapades 4 ปีที่แล้ว +3

      if u need more explanation let me know

    • @omergg4170
      @omergg4170 4 ปีที่แล้ว

      yea me too

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

      @@PetersExcapades Aaaaa... i don't think i understood anything

  • @Futureblur
    @Futureblur 4 ปีที่แล้ว +741

    I now know that I know nothing.

    • @tacomixen
      @tacomixen 4 ปีที่แล้ว +14

      Finally Jon Snow.

    • @chocpix
      @chocpix 4 ปีที่แล้ว +22

      I know what the best symbol is...
      [ ]
      The symbol of *brackeys*

    • @chocpix
      @chocpix 4 ปีที่แล้ว +5

      Yet... I know nothing else...

    • @ariarichards-
      @ariarichards- 4 ปีที่แล้ว +2

      Nice rhyme rap

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

      play.google.com/store/apps/details?id=com.UrazSoftware.StickyBall

  • @TehBunnieh
    @TehBunnieh 3 ปีที่แล้ว +10

    I had been trying so hard to get my player movement to work right with my camera movement the past few days and couldn't figure out this last missing part, and then find this video and noticed how easy it is if only I had brushed up on my math some more. Also, cinemachine... I forgot it existed... **buries head in hands**

  • @puchinbold
    @puchinbold 4 ปีที่แล้ว +192

    He always looks like he's about to start laughing

    • @dexah4842
      @dexah4842 3 ปีที่แล้ว +4

      i imagine him just going "ccch-chhh" the whole video

    • @nazarya5547
      @nazarya5547 3 ปีที่แล้ว +7

      İ don't think he looks like he will laugh he just looks happy.

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

      @@nazarya5547 yeah

  • @frankeeeej
    @frankeeeej 4 ปีที่แล้ว +23

    For camera-relative inputs I always use this line in my playerController:
    " movInput = (Cam.transform.forward * Input.GetAxisRaw("Vertical")) + (Cam.transform.right * Input.GetAxisRaw("Horizontal")); "
    Which is just one line of code and therefore superior ;p
    Apart from that, this cinemachine setup is waaaay superior than anything I ever made by myself, so I shal copy this for future projects, haha

    • @thomasdaly7270
      @thomasdaly7270 4 ปีที่แล้ว

      yea man I rate this

    • @Wonder_Verse_Tech
      @Wonder_Verse_Tech 2 ปีที่แล้ว

      When I hit Play , camera snaps to different position,(in front upward of the player)
      (It is working fine after that ,when I move mouse it moves the camera accordingly , but snap at starting the game is weird)
      (I have tried locking the cursor in start , but still snap problem exist)
      Why is this Happening , Please Help...

  • @YE55INE
    @YE55INE 4 ปีที่แล้ว +38

    If anyone's having snappy movement when going from a direction to the opposite one just uncheck "snap" in project settings-axis

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

      Thank you VERY much

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

      where do i find ''project settings-axis'' ???

    • @subarunatsuki1902
      @subarunatsuki1902 2 ปีที่แล้ว

      @@higorss Did you found it?

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

      @@subarunatsuki1902 I don't remember sorry. I gave up on my game dev career

    • @subarunatsuki1902
      @subarunatsuki1902 2 ปีที่แล้ว

      @@higorss No Problem, thx anyway :D

  • @JelleVermandere
    @JelleVermandere 4 ปีที่แล้ว +138

    Aah, the infamous cilinder-cube man, ready to boldly go where none have gone before!

    • @thekillerduck6977
      @thekillerduck6977 4 ปีที่แล้ว

      Lol

    • @hypehextech4680
      @hypehextech4680 4 ปีที่แล้ว

      yo Jelle! wassup

    • @JelleVermandere
      @JelleVermandere 4 ปีที่แล้ว

      HypehexWorks #neverstoplearning

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

      @@JelleVermandere xD nice

    • @dgameboss4963
      @dgameboss4963 4 ปีที่แล้ว

      th-cam.com/video/Yf9f8eC-Jdk/w-d-xo.html
      Hey there it's me again DGame_Boss and this time I took a challenge too make a complete Game in 24hrs and the game is a replica of a popular mobile game call ball blast...
      My apologies for spamming you this way...
      Enjoy the video and have a nice day.
      😁

  • @JesusSkywalker92
    @JesusSkywalker92 4 ปีที่แล้ว +8

    I've noticed that whenever you make a controller that uses a cylinder or capsule as the base, you make the scale 1.8 on the y axis (being 1.8 metres is the average height for a person) but the base height of cylinders and capsules is unity is 2 metres high on the y axis so by making is a scale of 1.8 you're essentially making a person that's 3.6 metres tall.

    • @peterkovac1406
      @peterkovac1406 2 ปีที่แล้ว

      as long as you keep proportions its ok, like map scale

  • @novarl4115
    @novarl4115 2 ปีที่แล้ว

    i love how this dude isnt even making content anymore and his stuff is still the first thing to show up when i search literally anything unity related

  • @loganjones5537
    @loganjones5537 4 ปีที่แล้ว +49

    Perfect this is exactly what I'm working on!

    • @emmetmayer
      @emmetmayer 4 ปีที่แล้ว +3

      Same, it's kinda creepy

    • @WarpedCyan
      @WarpedCyan 4 ปีที่แล้ว +5

      @@emmetmayer Orr somebody suggest it

  • @minticedteaenjoyer
    @minticedteaenjoyer 4 ปีที่แล้ว +7

    I swear, this guy is a psychic.

    • @veczz2509
      @veczz2509 4 ปีที่แล้ว

      Tell me about it lol

  • @FaithBasedBiz
    @FaithBasedBiz 3 ปีที่แล้ว +8

    I'm woking on a third person game with Legos, and this saved me from quitting, I'm serious, I was gonna stop making the game! TYSM, Brackeys! 😊

  • @danielmazzara7814
    @danielmazzara7814 4 ปีที่แล้ว +29

    This is the entire code. I´m using the 2019.3.0f5 version of unity. This code have UnityEngine.Vector3 cuz that solved me a problem. (this script is without the jumping part)
    using System.Collections;
    using System.Collections.Generic;
    using System.Numerics;
    using UnityEngine;
    public class ThirdPersonMovementScript : MonoBehaviour
    {
    public CharacterController controller;
    public Transform cam;
    public float speed = 6f;
    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;
    // Update is called once per frame
    void Update()
    {
    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    UnityEngine.Vector3 direction = new UnityEngine.Vector3(horizontal, 0f, vertical).normalized;
    if (direction.magnitude >= 0.1f)
    {
    float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
    transform.rotation = UnityEngine.Quaternion.Euler(0f, angle, 0f);
    UnityEngine.Vector3 moveDir = UnityEngine.Quaternion.Euler(0f, targetAngle, 0f) * UnityEngine.Vector3.forward;
    controller.Move(moveDir.normalized * speed * Time.deltaTime);
    }
    }
    }

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

      Thx for the code dude, i had some problem with mine as well so now i don't have to rewatch step by step

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

      thank you alot

    • @mrbob4104
      @mrbob4104 4 ปีที่แล้ว

      I had a problem cause I wrote Mathf.SmoothDamp instead of writing Mathf.SmoothDampAngle

    • @einwenigtot5448
      @einwenigtot5448 4 ปีที่แล้ว

      @Jovan Did you bind your camera to the "cam" variable and your CharacterController to the "controller" variable?

    • @nelson5953
      @nelson5953 4 ปีที่แล้ว

      When i copied and pasted it, most of the code that's supposed to be colored is white.
      Anyone know how to fix this?

  • @noahbeep3426
    @noahbeep3426 4 ปีที่แล้ว +62

    Why is my mouse inverted in cinemachine camera
    Edit: I figured it out lol, it's in the Third Person Camera settings, just tick the box next to inverted if you have the same issue

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

      wait... how do change that?

    • @stef9019
      @stef9019 4 ปีที่แล้ว +5

      @@Abldishabsmaj26193 Click on your Third Person Camera. In the "X Axis" tab, behind the "Input Axis Value" field, there's a "Invert" tickbox, make sure it's not ticked on.

    • @samysabi1166
      @samysabi1166 4 ปีที่แล้ว +3

      THANKS, I BEGUN TO THINK OF JUMPING OF THE WINDOW FOR THAT

    • @cupcake-gameclip5129
      @cupcake-gameclip5129 4 ปีที่แล้ว +1

      any idea why the character dont move at relative axis? regardless of where my mouse pointing, it seems to move WASD with respect to global x,y,z

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

      Thanks for the Edit!

  • @Alphzs
    @Alphzs 4 ปีที่แล้ว +40

    Everything works great... just in Unity editor, but after build - "Mouse look" is not working.

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

      Yeah

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

      me be caveman. me dont speak english

  • @anotherperson3450
    @anotherperson3450 4 ปีที่แล้ว +20

    It would be nice if this has a next part with animated character like running jumping and etc

    • @flint8182
      @flint8182 3 ปีที่แล้ว

      i would recommend watching seabastian league

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

    Here is the code with a jumping function & gravity
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class ThirdPersonMovement : MonoBehaviour
    {
    public CharacterController controller;
    public Transform cam;
    public float speed = 6f;
    public float gravity = -9.81f;
    public float jumpHeight = 3f;
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;
    Vector3 velocity;
    bool isGrounded;
    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;
    private void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
    if(isGrounded && velocity.y < 0)
    {
    velocity.y = -2f;
    }
    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);
    if(Input.GetButtonDown("Jump") && isGrounded)
    {
    velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
    }
    if (direction.magnitude >= 0.1f)
    {
    float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
    transform.rotation = Quaternion.Euler(0f, angle, 0f);
    Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
    controller.Move(moveDir.normalized * speed * Time.deltaTime);
    }
    }
    }

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

      Thank you! Which button do i Jump with? nothing happens when I hit "space"

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

      THANK YOU!!!! I just sorta rage quit trying to figure out a solution myself

    • @Lua_computa
      @Lua_computa 2 ปีที่แล้ว

      Do you think you could put it in a pastebin link so people can just easily add it?

    • @dawaysss7987
      @dawaysss7987 2 ปีที่แล้ว

      sad thing is its flappy bird u can spam space :skull:

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

      When I hit Play , camera snaps to different position,(in front upward of the player)
      (It is working fine after that ,when I move mouse it moves the camera accordingly , but snap at starting the game is weird)
      (I have tried locking the cursor in start , but still snap problem exist)
      Why is this Happening , Please Help...

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

    Too sad you stopped making videos here, I still watch your stuff on a regular basis. Thanks for creating!

  • @ChaosCain4
    @ChaosCain4 4 ปีที่แล้ว +30

    I'd already made something like this, but seeing it in such a nice package shows how much I have yet to learn. Thanks a lot for such an amazing video, so straightforward and clear

    • @Wonder_Verse_Tech
      @Wonder_Verse_Tech 2 ปีที่แล้ว

      When I hit Play , camera snaps to different position,(in front upward of the player)
      (It is working fine after that ,when I move mouse it moves the camera accordingly , but snap at starting the game is weird)
      (I have tried locking the cursor in start , but still snap problem exist)
      Why is this Happening , Please Help...

    • @ChaosCain4
      @ChaosCain4 2 ปีที่แล้ว

      @@Wonder_Verse_Tech Been a while since I did much with this, I'm not sure what you mean. It could be that it's reading the movement of the mouse from the moment you press unity's play button and move down back into the screen. Maybe don't read the mouse inputs on the very first frame of the game if that helps. Besides that I'm not sure, sorry. I hope you find a solution.

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

      the script wont let me add the character controller as a controller for it

  • @pietuuh2065
    @pietuuh2065 4 ปีที่แล้ว +12

    Finally! I've been waiting for this.

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

      Same. The last one broke cus unity updated

  • @user-ls7dl7ss6f
    @user-ls7dl7ss6f 4 ปีที่แล้ว +12

    *For those of you having issues with the player hovering over the ground when you move:*
    in the character controller make the skin width smaller (0.0001 worked for me)
    the player will still be above 0 but its very unnoticeable (like 0.005) and shouldnt effect gameplay

    • @harharrr9810
      @harharrr9810 2 ปีที่แล้ว

      not working for me :(

    • @YahayaBinBasiron
      @YahayaBinBasiron 2 ปีที่แล้ว

      @@harharrr9810 same

    • @CompisPaDum
      @CompisPaDum 2 ปีที่แล้ว

      @@harharrr9810 @Yahaya bin Basiron I had the same problem. The way I fixed it (which may not work for you) was to remove rigidbody component from any player objects.

  • @alexanderyankov666
    @alexanderyankov666 3 ปีที่แล้ว +15

    Is it possible to add gravity to this, too? I tried inserting a Rigid body component and it stated going crazy.

    • @Shalashaska-x5x
      @Shalashaska-x5x 3 ปีที่แล้ว +2

      rigidbody movement and character controller movement are two different types of movement, you cant just add a rigid body on a character controller

    • @marcopierdominici9317
      @marcopierdominici9317 3 ปีที่แล้ว +4

      Maybe is a little late but if you watch his video on first person movement he explains how to do it really well

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

      @@marcopierdominici9317 thanks man

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

      yo can change the Character Contoller by Rigid body you only must to change move(); for AddForce(); and delete * Time.deltatime

    • @afoccuc
      @afoccuc 3 ปีที่แล้ว

      @@catmunist marche pas

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

    You're really bringing me through my studies right now.... thank you so much!

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

      Oh are you in comp sci

  • @vedaantpatel8455
    @vedaantpatel8455 3 ปีที่แล้ว

    This man is a god. Brackeys you are the one person whose Unity tutorials actually helped and now you have taught me so much that I referred back to this video to start making my very own video game. Thank you... :)

  • @parvayalar3686
    @parvayalar3686 4 ปีที่แล้ว +4

    In the last part instead of creating movDir, use transform.forward. transform.forward points in the current forward direction of the Player Object.
    controller.Move(transform.forward * speed*Time.deltaTime);

  • @Drast_DBClips
    @Drast_DBClips 3 ปีที่แล้ว +3

    Ok i'm whatching these video rn and I wanted to tell you : "WoW" I'm in high school but I've seen that the real programming is soooo different, I admit that I'm having a lot of difficulties and the temptation of giving it away and just copy the code is really big but actually I'm here to learn not to copy so thank you for your explainations, I really appreciate how you make it look so simple, it is very motivational, God bless you!

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

      dont stop urself from copy and pasting , i learnt c# by copy and pasting different things i wanted together into one script , it helped me understand it alot more

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

    This tutorial was so good that I could feel the third person movement coming inside me whenever i played my game

  • @BamassacreGaming
    @BamassacreGaming 4 ปีที่แล้ว +18

    Me coming into life always wanting to code games.
    Me hearing Quaternion.Euler and looking back at my code and getting a migraine

  • @soceity7102
    @soceity7102 4 ปีที่แล้ว +159

    Sees this video after 1 month of working on third person movement
    Me: internal screeching

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

      same

    • @Cheepe1000
      @Cheepe1000 4 ปีที่แล้ว

      same, worst part tried using Cinemachine and Character Controller and couldn't get the handle of it...

    • @s7887177
      @s7887177 4 ปีที่แล้ว

      same here.

    • @davestomper3428
      @davestomper3428 4 ปีที่แล้ว

      I cant get it working either

    • @monkeyrobotsinc.9875
      @monkeyrobotsinc.9875 4 ปีที่แล้ว +1

      wow, only one month? lucky you.

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

    So far these videos are giving me knowledge of how to build a base reference for a game that I know is going to take a while for me to make even with the help of my team currently still trying to put together 😂

  • @IFCreativeAlt
    @IFCreativeAlt 3 ปีที่แล้ว +24

    10:56
    brackeys: normalize that so you dont go faster diagonaly.
    me: hmmm good mechanic not normalizing

  • @PotatoTheProgrammer
    @PotatoTheProgrammer 4 ปีที่แล้ว +13

    when i move the view in scene view its sensitivity goes to a very high number, and the camera moves very fast

    • @cohenlockwood6066
      @cohenlockwood6066 3 ปีที่แล้ว

      change the speed of the y axis or x axis depending on which axis you want to slow down

  • @tolafia6708
    @tolafia6708 2 ปีที่แล้ว

    Where would i be without this channel...It's too useful for things i forget all the time

  • @yunglimp1996
    @yunglimp1996 3 ปีที่แล้ว +7

    Why does non of my code ever work when I follow these tutorials.... I literally spend hours trynna work this out.

    • @yunglimp1996
      @yunglimp1996 3 ปีที่แล้ว

      @@PranjayMittal yep I got it to work ahhaha

    • @yunglimp1996
      @yunglimp1996 3 ปีที่แล้ว

      @@PranjayMittal I takes me way to long tho 😭😭😭

    • @vfwarlordforever9589
      @vfwarlordforever9589 3 ปีที่แล้ว

      It doesnt work for me. The console says I need a ";" after speed in the last like. But if I dont type in Time, deltaTime); , it causes 7 more errors. Help!!!

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

    Great video ! Just one thing, if you normalized your direction vector it'll be useless to check if its length is greater than 0.1 (if you do this to simulate a stick deadzone).

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

    IT WORKS!!!
    only a few things (mostly doubts):
    -it hits me with an error of "the variable of the orientation of camera_3d has not been assigned" but it doesn´t break the game or stop it from working so..... Idk
    -when I put rigidbody and box collider to the character it get this weird bug in which is im looking at certain weird angles the character would "teleport" (and this happen with and without freezing rotation) (and yes I know the engine tells me to not put box collider because character controller but if I don´t put it the character just falls to the void, so I put the collider to the graphics itself, maybe there is the problem but again, it doesn´t let me put it in the player object, without it the rigidbody doesn´t work and without the rigidbody she isn´t affected by gravity)
    - 18:16 this didn´t work just with layers, I put a box collider to one wall and it worked so I guess I need to put box colliders to every obstacle right? I mean they have to have collision in the first place so this one isn´t that big of a deal

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

    I've been banging my head looking for a good tutorial on this!!! Just in time, Tysm :D

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

    That was exactly what i need right now, i love this channel so much

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

    14:00 Correction: I would reccomend in the Atan2 line to write instead of this: float targetRotation = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg; this: float targetRotation = Mathf.Atan2(MoveX, MoveY) * Mathf.Rad2Deg; This will fix some errors that i had. Hope it helped ; )

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

    OMGGG YESSS. I NEEDED THISSSSSSS.
    I usually prefer doing everything myself. So cinemechine is something I dnt really like. Luckily I know how to make my own 3rd person camera and collision. Then apply the movement script to it. Thanks so much brackeys ur the best!

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

      I get what you are saying but in terms of real-world applications this is a godsent package. It does so much for you and saves so much time. And time is money. No need to reinvent the wheel.

    • @dgameboss4963
      @dgameboss4963 4 ปีที่แล้ว

      th-cam.com/video/Yf9f8eC-Jdk/w-d-xo.html
      Hey there it's me again DGame_Boss and this time I took a challenge too make a complete Game in 24hrs and the game is a replica of a popular mobile game call ball blast...
      My apologies for spamming you this way...
      Enjoy the video and have a nice day.
      😁

    • @efaz6809
      @efaz6809 4 ปีที่แล้ว

      ArnoldsK Yh I get wht ur saying but I’m kind of still learning. So doing this will, in a way make me more confident with the things I’m learning, as everything I produce is made from scratch by me. It’s hard to explain but yh

    • @efaz6809
      @efaz6809 4 ปีที่แล้ว

      DGame Boss video’s been removed

  • @xavierbradford5528
    @xavierbradford5528 4 ปีที่แล้ว +14

    His voice is so soothing I’m watching this while coding something else lol

    • @dgameboss4963
      @dgameboss4963 4 ปีที่แล้ว

      th-cam.com/video/Yf9f8eC-Jdk/w-d-xo.html
      Hey there it's me again DGame_Boss and this time I took a challenge too make a complete Game in 24hrs and the game is a replica of a popular mobile game call ball blast...
      My apologies for spamming you this way...
      Enjoy the video and have a nice day.
      😁

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

      yes its asmr i listen to it while I play Osu

  • @safdardeveloper3804
    @safdardeveloper3804 2 ปีที่แล้ว

    You are the only one youtuber who kept the contents simple and useful

    • @Viltzu-hk5wh
      @Viltzu-hk5wh 2 ปีที่แล้ว

      Yeah, but like all people the man gotta have his own time. we owe him at least that much.

    • @safdardeveloper3804
      @safdardeveloper3804 2 ปีที่แล้ว

      @@Viltzu-hk5wh I don't know what you mean.

  • @iangraham6730
    @iangraham6730 4 ปีที่แล้ว +4

    Jason is top class, have been following him for a long time, well worth a sub!

  • @666nevermore
    @666nevermore 4 ปีที่แล้ว +5

    How do you convert those values into a rigid body? working with character controller is almost useless, you can't interact with most of things. I tried a couple of ways but it seems like RigidBody doesn't like that Vector3 moveDir for some reason

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

    This helped me a lot, i was struggling with movement and camera composition. But with your help, i manage to do the style i was looking for.... Thanks

  • @puruarora3584
    @puruarora3584 4 ปีที่แล้ว +4

    Finally ❤❤
    Pls pls also make a video on humanoid movements...i am tired of using ethan🌚🌚

  • @DeveloperJake
    @DeveloperJake 4 ปีที่แล้ว +8

    Help my character keeps teleporting up on the Y axis every time I start the game then press a movement key
    What’s happening?

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

      Same thing happened with me adjust the character controller's collider. that will solve all your problems

    • @manuelgeissberger2910
      @manuelgeissberger2910 4 ปีที่แล้ว

      @@kushagrapamnani868 Thanks man

  • @derekw8039
    @derekw8039 4 ปีที่แล้ว

    I have spent a long time searching the internet for a way to smooth player rotation the way you do here! Thank you thank you THANK YOU!!!!

  • @af5772
    @af5772 3 ปีที่แล้ว +5

    I need help with something: is there a way I can make it that when the character moves, moves and rotates where the camera is pointing; but in a way that when the character is standing still and I start moving the character doesnt rotate on himself and instead turn around a radius
    Edit: essentially if I press a or d or s the character STRAFES IN THAT DIRECTION. then if I press w it follows where the camera is pointing, but say I'm standing still and I'm pointing the camera behind the character and then I press W, i don't want him to spin on himself like that, I want him to turn around a radius, or mayhe the camera to snap back to where the character is looking

    • @peterguest6011
      @peterguest6011 3 ปีที่แล้ว

      Did you manage to find a solution? I really want to be able to do this

    • @af5772
      @af5772 3 ปีที่แล้ว

      @@peterguest6011 I kinda gave up but then found a way to figure it out. If you think about it the movement system for a car is quite similar minus the strafing left right. But it's has the directional input with mouse and it has reverse. So that's a good starting point. If you have any luck figuring it out can you contact me.

    • @peterguest6011
      @peterguest6011 3 ปีที่แล้ว

      @@af5772 Thanks for the reply :) With a bit of poking around I managed to get it to sort of work.
      I changed float targetAngle to just = cam.eulerAngles.y removing the Mathf.Atan2 direction and Rad2Deg stuff. Then changed Vector3 moveDir to = Quaternion.Euler(0f, targetAngle, 0f) * direction instead of Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward
      It works but my player moves slightly backwards when strafing which I don't know how to fix as I have no idea what I'm doing with coding!
      Hope this helps!

  • @Juleru
    @Juleru 4 ปีที่แล้ว +8

    I followed your "first person movement" tutorial video (2019), which was extremly easy to follow but after watching this, I'm now wondering: Can you use Cinemachine for a first person player too?

    • @benjioffdsv
      @benjioffdsv 4 ปีที่แล้ว

      yeah but its pointless

    • @Juleru
      @Juleru 4 ปีที่แล้ว

      @@benjioffdsv Care to elaborate?

    • @guest1805
      @guest1805 2 ปีที่แล้ว

      @@Juleru sure

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

    ! I was trying to make a third person camera system for my game but it wasn't really working. Despite the differences in setup, this worked for me without having to change much. Thanks for making this tutorial so flexible/customisable

  • @flannagus4787
    @flannagus4787 4 ปีที่แล้ว +4

    yes yes it worked! now im feeling a surge of dopamine, thats sure to stop after some time, thanks!

  • @theangrycoder4680
    @theangrycoder4680 4 ปีที่แล้ว +8

    10:11 “horizontal” and “vertical” is always mapped to these keys? Its Default for Unity? I guess its changeable somewhere?

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

      You can change that in Edit > Project Settigns > Input Manager > Axis And there you can choose positive and negative keys. Hope I helped a bit :D

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

    Thanks!!!This video has what I was looking for!!

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

    Hello,
    Thank you. It really helps me with the Drone controller.
    However, I don't know why I repeated all steps as you showed but I can't move backward with keyboard S (it's always forward) or the keyboard arrow Down. I would like to ask for help if anyone know?

    • @alainthenot2309
      @alainthenot2309 2 ปีที่แล้ว

      same thing happens to me

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

      Hello! I don't actually know if you solved this or if you still need it, but i have faced the same problem and actually found out the solution!
      Make sure that line 23 IS
      float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
      and NOT
      float targetAngle = Mathf.Atan2(direction.x, direction.y) * Mathf.Rad2Deg + cam.eulerAngles.y;
      Cheers!

  • @Zaine7673
    @Zaine7673 4 ปีที่แล้ว +5

    This script seems so elegant 😍 but how can you adjust it so player moves backwards when you press S instead of turning around and facing that way?

    • @jmaslaki
      @jmaslaki 3 ปีที่แล้ว

      I wanna know this too

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

    Wish you still posted. this helped SO MUCH!

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

    Can you give a breakdown as to how you set up the scene as of the beginning of the video, or otherwise upload the project file to github?

    • @blackshadow8041
      @blackshadow8041 3 ปีที่แล้ว

      th-cam.com/video/YtzIXCKr8Wo/w-d-xo.html&ab_channel=Brackeys

  • @Pragma020
    @Pragma020 3 ปีที่แล้ว +4

    I spent 2 months learning quaternions , trigonometry, dot product to write my camera from scratch, melding them in to disfigured logic that works together.
    This is my pain for not using tutorials, like I know enough to accomplish my goals.
    I am so sad right now, I feel defeated.
    I felt like I was finally winning, then they used a trap card and obliterates my whole crew.

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

      shit.

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

      Well at least you learned something...

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

      What?

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

      Pain...

  • @aob3366
    @aob3366 3 ปีที่แล้ว

    I'm in love with this intro

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

    Beautiful tutorial. Got everything up and running but would love to know how to edit this script so that the camera only pans when holding right mouse button instead of tracking 100% of mouse movement... anybody have an idea?

    • @HarrisonK08
      @HarrisonK08 4 ปีที่แล้ว

      Idk but if you get an answer tell me

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

    Is there any way to implement jumping in this controller? I'm having trouble figuring out how to do it.

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

      Just add the same code as the one from his first-person camera controller video...

    • @dk3390
      @dk3390 4 ปีที่แล้ว

      All you have to do is just add some force on Y instead of 0f

    • @that_guyu_know6019
      @that_guyu_know6019 3 ปีที่แล้ว

      @@Exarhadsgfds This works very well, in the first person video he added a velocity system with its own artificial gravity and it works great!

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

    I was fighting with camera and player movement for a few weeks... After 20 minutes of this video this is better than everything that I got....

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

    Does someone know how I can change Ethan's script from standard assets to move where the camera is pointing?

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

    Me: *Starts making a third person game*
    Brackeys: *Uploads the video of my topic*
    Me: *Impossible*
    Edit: Keep it up man!

  • @ehansytaxian
    @ehansytaxian 2 ปีที่แล้ว

    This is the best intro ever!

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

    If you're following along with this tutorial and can't find the Cinemachine tab, it's now under the GameObject tab.

  • @jamestacular
    @jamestacular 4 ปีที่แล้ว +5

    Any reason why my dude is hopping every time I try to move him? He still moves in the direction I want him but is doing this weird skip on initial keypress.

  • @Aly_.3_3
    @Aly_.3_3 2 ปีที่แล้ว

    Amazing man amazing no one provide free knowledge like this its ridiculous....
    I checked out 20 channels on you tube but no one is like you💥

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

    For everyone that can't keep up with the code,
    Set the play time at 0.75x and it will sound like a normal talking speed

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

    Awesome video! Would've been even better with the new input system, since v1 is officially out it might be worth checking out.

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

      Takes a bit of tweaking but works well with the new input system. Just haven't figured out how to manage the movement angle in relation to the camera using the new input yet

    • @MAxAMILLIoN757
      @MAxAMILLIoN757 2 ปีที่แล้ว

      @@l2hetoric Please reply here with the code if you figure it out

  • @baran9086
    @baran9086 3 ปีที่แล้ว

    I can't say how thankful i am for this video. It really helped me a LOT. Thank you very much!!!

  • @hoonmaster965
    @hoonmaster965 4 ปีที่แล้ว +5

    is there anyway to make it so that you can use rigid body for this, because when i tried it the character just spazzed out.

    • @ph0ax497
      @ph0ax497 4 ปีที่แล้ว +3

      @@sensory.aiden201 read the comments first. I've posted the whole code for this:
      i've implemented that camera movement, 1:1 to a rigidbody. Everything made by myself (with help of other tutorials).
      Enjoy:
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using UnityEngine.PlayerLoop;
      public class PlayerMovement : MonoBehaviour
      {
      public float walkSpeed;
      public float runSpeed;
      public float playerJumpForce;
      public ForceMode appliedForceMode;
      public float currentSpeed;
      public float turnSmoothTime = 0.1f;
      public Transform groundCheck;
      public Transform cam;
      public float groundDistance = 0.4f;
      public LayerMask groundMask;
      public bool isGrounded;
      float turnSmoothVelocity;
      private float _xAxis;
      private float _zAxis;
      private Rigidbody _rb;
      private bool _isShiftPressedDown;
      private bool jump;
      private bool up;
      private Vector3 movement;
      private Vector3 direction;
      private void Start()
      {
      _rb = GetComponent();
      _rb.constraints = RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
      }
      private void Update()
      {
      _xAxis = Input.GetAxis("Horizontal");
      _zAxis = Input.GetAxis("Vertical");
      direction = new Vector3(_xAxis, 0f, _zAxis).normalized;
      currentSpeed = _isShiftPressedDown ? runSpeed : walkSpeed;
      isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
      Debug.Log(isGrounded);
      if (Input.GetButtonDown("Jump") && isGrounded)
      {
      jump = true;
      }
      up = direction.magnitude >= 0.1f;
      }
      private void FixedUpdate()
      {
      if (jump)
      {
      PlayerJump(playerJumpForce, appliedForceMode);
      jump = false;
      }
      if (up)
      {
      float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
      float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
      transform.rotation = Quaternion.Euler(0f, angle, 0f);
      Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
      movement = moveDir.normalized * currentSpeed * Time.deltaTime;
      _rb.MovePosition(transform.position +movement);
      }
      }
      private void OnGUI()
      {
      _isShiftPressedDown = Input.GetKey(KeyCode.LeftShift);
      }
      private void PlayerJump(float jumpForce, ForceMode forceMode)
      {
      _rb.AddForce(jumpForce * _rb.mass * Time.deltaTime * Vector3.up, forceMode);
      }
      }

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

      @@ph0ax497 Hey this all works great...except for the fact that my character falls through the ground, how do I stop this thanks.

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

      @@KlutzOfAMan have you put on it collider? xd

    • @lilstringcheese
      @lilstringcheese 4 ปีที่แล้ว

      @@ph0ax497 When I used the script my character flew straight up and when I moved in an x or z direction my character flew in that direction to without stopping. Do you know what might be happening?

  • @olqb9532
    @olqb9532 3 ปีที่แล้ว +4

    I'm quite new to this, a lot of tutorials recommend to have the actual movement in FixedUpdate. Is there a specific reason Brackeys does it differently? I get that Time.deltaTime works around the fps resctrictions, but to my understanding it would still be best practice to have it in FixedUpdate. What am I missing?

    • @Kazuma593
      @Kazuma593 3 ปีที่แล้ว +4

      I'm new as well, but I do know the reason for that. FixedUpdate is the update for the physics engine which runs on a fixed interval. Update happens every time a frame is rendered. If people bind things to Update instead of Fixed Update, the more FPS you have, the more often your functions are being called.
      That's also what creates weird issues with games like Elder Scrolls or Fallout, so usually they just add a 30 fps cap instead of tying it to something other than frame rate.
      With Unity we can use FixedUpdate to tie it to the interval refresh of the physics engine. This way whether you get 1fps or 144fps the lines of code are still executed in the same interval.

  • @user-chuquangvuong
    @user-chuquangvuong 11 หลายเดือนก่อน

    How you provide the information is so interesting and easy to understand man, you got one subscribe !

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

      Lol he quit ages ago

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

      ​@@timurradman3999but did he really??

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

    NOTE: Cinemachine menu has moved to GameObject -> Cinemachine

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

    7:21 (Dont mind saving my spot)

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

    I FINALLY MANAGED TO FOLLOW IT TO THE END !!!!!

  • @zaidyousef4308
    @zaidyousef4308 4 ปีที่แล้ว +24

    Can you Please make a wallruning tutorial?
    pretty please :)

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

      Yesss or u cannot do that!

    • @piotrus5457
      @piotrus5457 4 ปีที่แล้ว

      But do that with character controller not RB :)