Third Person Movement In Unity 6 (Beginner Tutorial) — Transcript
Full transcript
- 0:00In this video, I'll show you how to
- 0:01create this simple third-person
- 0:02controller where you can look around and
- 0:04jump and all of that stuff. So, let's
- 0:06begin.
- 0:07But, we'll start right here with a very
- 0:09basic scene. All I have is a ground
- 0:11right here. It literally has nothing.
- 0:12It's just a cube. But, what I'll do is
- 0:14right click over here and go to 3D
- 0:16object and choose a capsule. This will
- 0:18be the player. I'll just call it player
- 0:20and I'll put it at 000 and just a bit up
- 0:23like that. Then, I'll just drag my red
- 0:24material onto that so I can see the
- 0:26player better. Then, hopefully you also
- 0:28have a main camera. Drag this onto the
- 0:30player. Just put it at 000 for the
- 0:33player. It doesn't really matter because
- 0:34we'll handle it all with code. And now,
- 0:36what we can do is right click and create
- 0:38a new mono behavior script which I'll
- 0:40just call third-person controller.
- 0:43Open that up. In here, let's delete the
- 0:45start function and then at the top, we
- 0:47will be using UnityEngine.InputSystem
- 0:51like so. And then, we'll add these
- 0:52brackets above the class where we will
- 0:54write require component and type of
- 0:57rigid body. So, when we add this script
- 0:59onto the player, it will automatically
- 1:01also add a rigid body. Now, let's add a
- 1:03public transform called cam. We also
- 1:06need a public float called move speed.
- 1:09I'll set this to maybe six. And let's do
- 1:11a public float called [music] jump
- 1:13force. So, how high we jump. I'll set
- 1:16this to a seven.
- 1:17Let's add a public float called mouse
- 1:20sensitivity. I'll set this to 0.12.
- 1:24We'll also have a public float called
- 1:26camera distance. I'll set this to, let's
- 1:29say, five. And a public float called
- 1:32camera height. So, how high it is above
- 1:34the player. I'll set this to a 1.6. Now,
- 1:37we just need a private rigid body called
- 1:39RB, a private float called yaw, and a
- 1:42private float called pitch. These will
- 1:45be the values for our camera when it
- 1:47looks around. Then, let's add an awake
- 1:49function and in here, we'll simply do RB
- 1:51equals get component rigid body so we
- 1:53have the rigid body. Then, we can have
- 1:55an RB.freezeRotation
- 1:57to be true so the player doesn't fall
- 2:00over and we'll have a cursor.lockState
- 2:03equals cursor lock mode.locked
- 2:06so that our cursor is locked to the
- 2:08middle of the screen. This will
- 2:09automatically also hide the mouse. Now
- 2:11under these we'll also have a fixed
- 2:14update which we'll be using and a late
- 2:16update, but we won't add anything yet to
- 2:18those because under we're going to add a
- 2:20void called look. So here we will handle
- 2:23all of the looking with the camera. In
- 2:25here we'll do a Vector2 called mouse
- 2:27delta equals
- 2:29mouse.current.delta.readValue.
- 2:32So this is basically how much we move
- 2:34the mouse basically between each frame.
- 2:37[music] Let's now do your plus equals
- 2:39mouse sensitivity
- 2:43multiplied with our mouse sensitivity.
- 2:46Let's also have a pitch minus equals
- 2:49where we do mouse delta.y times our
- 2:52mouse sensitivity and we can do pitch
- 2:54one more time equals mathf.clamp
- 2:57where we input our pitch and then we say
- 2:59the minimum value which I think should
- 3:01be minus 40 [music] and the maximum
- 3:03should be 70. So this is how far you can
- 3:05look up and down basically.
- 3:07>> [music]
- 3:07>> And oops, not clamp 01 just clamp like
- 3:09that. And now we can do transform
- 3:12.rotation equals Quaternion.Euler
- 3:150f, yaw, 0f. This will be because when
- 3:20we look from side to side the player
- 3:22should actually rotate and not the
- 3:24actual camera. Now let's do a function
- 3:26which returns a Vector3 so do Vector3
- 3:29get move input because we're using the
- 3:32new input system we'll do var kb for
- 3:34keyboard equals keyboard.current
- 3:37so we don't have to write it multiple
- 3:39times. Then we can do a float x equals
- 3:410f, a c equals 0. And now we can check
- 3:45if kb. Let's do [music] the w key first
- 3:50.isPressed well then we can set C to
- 3:53plus equals one. And let's copy this
- 3:55multiple times. Let's do it three times
- 3:58more. One, two, three. The next one will
- 4:00be the S key, where we will set C to
- 4:02minus one. Then we'll do the D key, and
- 4:06this will be for our X, so X plus equals
- 4:08one. And then we'll do minus equals one
- 4:11here for our A key. And now we can
- 4:14simply at the bottom return our new
- 4:16vector three, where we input X, where we
- 4:19input X {comma} zero {comma} C. And
- 4:21we'll do dot normalized right here, so
- 4:24it's not above one. Now we'll do a
- 4:25simple void jump. In here we'll check if
- 4:28keyboard.current.spacekey.waspressed
- 4:30this frame, and is grounded, [music]
- 4:35which is a function we'll create in just
- 4:37a [music] minute. Well, if these are
- 4:38both true, we can do rb.addforce,
- 4:41where we can just do vector3.up
- 4:43multiplied with our jump force, {comma}
- 4:46ForceMode.Impulse,
- 4:48which means all the force happens all at
- 4:51once. Let's now do this grounded, so we
- 4:53do bool is grounded like this, so it
- 4:56turns either true or false. And here we
- 4:58just return a physics.raycast,
- 5:02where we input our transform.position,
- 5:04which is where we're going to shoot our
- 5:05ray from, and then we'll shoot
- 5:07vector3.down, so basically downwards.
- 5:10And then we can set the max distance to
- 5:11be 1.1. So if this ray hits something
- 5:14under the player, well, this means we're
- 5:16on the ground. Now let's do a void
- 5:18position camera to actually be
- 5:20positioned the camera right. And here
- 5:21we'll do Quaternion cam rotation equals
- 5:25Quaternion.Euler,
- 5:27where we're going to input pitch {comma}
- 5:29yaw, {comma} zero. Then we can do a
- 5:31vector three, where we do focus point
- 5:35equals transform.position
- 5:38plus our vector three.up times our
- 5:41camera height. And now we can do
- 5:43cam.position equals focus point minus
- 5:46our cam rotation, multiplied with vector
- 5:493. forward, multiplied with camera
- 5:52distance. [music] And we can do
- 5:54cam.rotation equals our camera rotation,
- 5:57which we already calculated up here.
- 5:59Now, we just need a void move, and in
- 6:01here we'll do a vector 3 called input,
- 6:04where we'll set that equal to get move
- 6:06input.
- 6:07And we'll do a vector 3 called move
- 6:10direction equals transform.forward
- 6:13multiplied with input.c plus
- 6:16transform.right
- 6:18multiplied with input.x.
- 6:21Now, we can do [music] vector 3 velocity
- 6:24equals our move directions times our
- 6:27move speed. And let's do velocity.y
- 6:30equals rb.linearvelocity.y.
- 6:33And we can now do rb.linearvelocity
- 6:37equals our velocity. Perfect. Now, we
- 6:39just need to call off these functions up
- 6:41here in update, fixed update, and late
- 6:43update. Inside of the normal update
- 6:45function, we'll call our look, and we'll
- 6:47also call our jump.
- 6:50And this is basically where we read
- 6:51input, or if something only happens on
- 6:53an instance, that's why it's in here in
- 6:55update. And in our fixed update, we're
- 6:57going to add our move. So, physics are
- 6:59very good to do inside of the fixed
- 7:01update, so that's why we do our movement
- 7:03here. And for our late update, we'll do
- 7:05our position camera.
- 7:07This is quite important, or else our
- 7:09camera could look jittery, so it's good
- 7:11to put inside of the late update
- 7:13function. And that's everything for the
- 7:14script. Now, we just have to go back
- 7:16into Unity. In here, we'll click on the
- 7:17player and drag the third-person
- 7:19controller onto here. And now, we just
- 7:21need to set the camera, so drag the main
- 7:23camera onto here, and let's try to play.
- 7:26And yep, we can look around, we can walk
- 7:28around, and we can jump.
- 7:30And if you can't do any of that, and you
- 7:31have an error, maybe you're using the
- 7:33wrong input system. Just go to edit
- 7:34project settings, clear, scroll down,
- 7:35other settings, configuration, and set
- 7:36active input handling to both. If you
- 7:38found this video very useful, I know
- 7:39you'll like my school community, where
- 7:41my students go from a complete beginner
- 7:43all the way to publishing their own
- 7:45games. Check it out. That's the top link
- 7:47in the description. I really think
- 7:48you'll like it. We have a bunch of
- 7:50courses in there. You can get direct
- 7:52access to ask me any question anytime.
- 7:54[music] I'll literally be your direct
- 7:55mentor. So, check it out. Top link in
- 7:57the description and have an amazing day.
About this transcript
This page contains the full transcript of Third Person Movement In Unity 6 (Beginner Tutorial) by Unity Unlocked, generated from the public captions YouTube serves with the video. The transcript has 1,406 words across 210 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.