YouTube2Text

Third Person Movement In Unity 6 (Beginner Tutorial) — Transcript

by Unity Unlocked · 1,406 words · 210 segments · language en · Watch on YouTube

Full transcript

  1. 0:00In this video, I'll show you how to
  2. 0:01create this simple third-person
  3. 0:02controller where you can look around and
  4. 0:04jump and all of that stuff. So, let's
  5. 0:06begin.
  6. 0:07But, we'll start right here with a very
  7. 0:09basic scene. All I have is a ground
  8. 0:11right here. It literally has nothing.
  9. 0:12It's just a cube. But, what I'll do is
  10. 0:14right click over here and go to 3D
  11. 0:16object and choose a capsule. This will
  12. 0:18be the player. I'll just call it player
  13. 0:20and I'll put it at 000 and just a bit up
  14. 0:23like that. Then, I'll just drag my red
  15. 0:24material onto that so I can see the
  16. 0:26player better. Then, hopefully you also
  17. 0:28have a main camera. Drag this onto the
  18. 0:30player. Just put it at 000 for the
  19. 0:33player. It doesn't really matter because
  20. 0:34we'll handle it all with code. And now,
  21. 0:36what we can do is right click and create
  22. 0:38a new mono behavior script which I'll
  23. 0:40just call third-person controller.
  24. 0:43Open that up. In here, let's delete the
  25. 0:45start function and then at the top, we
  26. 0:47will be using UnityEngine.InputSystem
  27. 0:51like so. And then, we'll add these
  28. 0:52brackets above the class where we will
  29. 0:54write require component and type of
  30. 0:57rigid body. So, when we add this script
  31. 0:59onto the player, it will automatically
  32. 1:01also add a rigid body. Now, let's add a
  33. 1:03public transform called cam. We also
  34. 1:06need a public float called move speed.
  35. 1:09I'll set this to maybe six. And let's do
  36. 1:11a public float called [music] jump
  37. 1:13force. So, how high we jump. I'll set
  38. 1:16this to a seven.
  39. 1:17Let's add a public float called mouse
  40. 1:20sensitivity. I'll set this to 0.12.
  41. 1:24We'll also have a public float called
  42. 1:26camera distance. I'll set this to, let's
  43. 1:29say, five. And a public float called
  44. 1:32camera height. So, how high it is above
  45. 1:34the player. I'll set this to a 1.6. Now,
  46. 1:37we just need a private rigid body called
  47. 1:39RB, a private float called yaw, and a
  48. 1:42private float called pitch. These will
  49. 1:45be the values for our camera when it
  50. 1:47looks around. Then, let's add an awake
  51. 1:49function and in here, we'll simply do RB
  52. 1:51equals get component rigid body so we
  53. 1:53have the rigid body. Then, we can have
  54. 1:55an RB.freezeRotation
  55. 1:57to be true so the player doesn't fall
  56. 2:00over and we'll have a cursor.lockState
  57. 2:03equals cursor lock mode.locked
  58. 2:06so that our cursor is locked to the
  59. 2:08middle of the screen. This will
  60. 2:09automatically also hide the mouse. Now
  61. 2:11under these we'll also have a fixed
  62. 2:14update which we'll be using and a late
  63. 2:16update, but we won't add anything yet to
  64. 2:18those because under we're going to add a
  65. 2:20void called look. So here we will handle
  66. 2:23all of the looking with the camera. In
  67. 2:25here we'll do a Vector2 called mouse
  68. 2:27delta equals
  69. 2:29mouse.current.delta.readValue.
  70. 2:32So this is basically how much we move
  71. 2:34the mouse basically between each frame.
  72. 2:37[music] Let's now do your plus equals
  73. 2:39mouse sensitivity
  74. 2:43multiplied with our mouse sensitivity.
  75. 2:46Let's also have a pitch minus equals
  76. 2:49where we do mouse delta.y times our
  77. 2:52mouse sensitivity and we can do pitch
  78. 2:54one more time equals mathf.clamp
  79. 2:57where we input our pitch and then we say
  80. 2:59the minimum value which I think should
  81. 3:01be minus 40 [music] and the maximum
  82. 3:03should be 70. So this is how far you can
  83. 3:05look up and down basically.
  84. 3:07>> [music]
  85. 3:07>> And oops, not clamp 01 just clamp like
  86. 3:09that. And now we can do transform
  87. 3:12.rotation equals Quaternion.Euler
  88. 3:150f, yaw, 0f. This will be because when
  89. 3:20we look from side to side the player
  90. 3:22should actually rotate and not the
  91. 3:24actual camera. Now let's do a function
  92. 3:26which returns a Vector3 so do Vector3
  93. 3:29get move input because we're using the
  94. 3:32new input system we'll do var kb for
  95. 3:34keyboard equals keyboard.current
  96. 3:37so we don't have to write it multiple
  97. 3:39times. Then we can do a float x equals
  98. 3:410f, a c equals 0. And now we can check
  99. 3:45if kb. Let's do [music] the w key first
  100. 3:50.isPressed well then we can set C to
  101. 3:53plus equals one. And let's copy this
  102. 3:55multiple times. Let's do it three times
  103. 3:58more. One, two, three. The next one will
  104. 4:00be the S key, where we will set C to
  105. 4:02minus one. Then we'll do the D key, and
  106. 4:06this will be for our X, so X plus equals
  107. 4:08one. And then we'll do minus equals one
  108. 4:11here for our A key. And now we can
  109. 4:14simply at the bottom return our new
  110. 4:16vector three, where we input X, where we
  111. 4:19input X {comma} zero {comma} C. And
  112. 4:21we'll do dot normalized right here, so
  113. 4:24it's not above one. Now we'll do a
  114. 4:25simple void jump. In here we'll check if
  115. 4:28keyboard.current.spacekey.waspressed
  116. 4:30this frame, and is grounded, [music]
  117. 4:35which is a function we'll create in just
  118. 4:37a [music] minute. Well, if these are
  119. 4:38both true, we can do rb.addforce,
  120. 4:41where we can just do vector3.up
  121. 4:43multiplied with our jump force, {comma}
  122. 4:46ForceMode.Impulse,
  123. 4:48which means all the force happens all at
  124. 4:51once. Let's now do this grounded, so we
  125. 4:53do bool is grounded like this, so it
  126. 4:56turns either true or false. And here we
  127. 4:58just return a physics.raycast,
  128. 5:02where we input our transform.position,
  129. 5:04which is where we're going to shoot our
  130. 5:05ray from, and then we'll shoot
  131. 5:07vector3.down, so basically downwards.
  132. 5:10And then we can set the max distance to
  133. 5:11be 1.1. So if this ray hits something
  134. 5:14under the player, well, this means we're
  135. 5:16on the ground. Now let's do a void
  136. 5:18position camera to actually be
  137. 5:20positioned the camera right. And here
  138. 5:21we'll do Quaternion cam rotation equals
  139. 5:25Quaternion.Euler,
  140. 5:27where we're going to input pitch {comma}
  141. 5:29yaw, {comma} zero. Then we can do a
  142. 5:31vector three, where we do focus point
  143. 5:35equals transform.position
  144. 5:38plus our vector three.up times our
  145. 5:41camera height. And now we can do
  146. 5:43cam.position equals focus point minus
  147. 5:46our cam rotation, multiplied with vector
  148. 5:493. forward, multiplied with camera
  149. 5:52distance. [music] And we can do
  150. 5:54cam.rotation equals our camera rotation,
  151. 5:57which we already calculated up here.
  152. 5:59Now, we just need a void move, and in
  153. 6:01here we'll do a vector 3 called input,
  154. 6:04where we'll set that equal to get move
  155. 6:06input.
  156. 6:07And we'll do a vector 3 called move
  157. 6:10direction equals transform.forward
  158. 6:13multiplied with input.c plus
  159. 6:16transform.right
  160. 6:18multiplied with input.x.
  161. 6:21Now, we can do [music] vector 3 velocity
  162. 6:24equals our move directions times our
  163. 6:27move speed. And let's do velocity.y
  164. 6:30equals rb.linearvelocity.y.
  165. 6:33And we can now do rb.linearvelocity
  166. 6:37equals our velocity. Perfect. Now, we
  167. 6:39just need to call off these functions up
  168. 6:41here in update, fixed update, and late
  169. 6:43update. Inside of the normal update
  170. 6:45function, we'll call our look, and we'll
  171. 6:47also call our jump.
  172. 6:50And this is basically where we read
  173. 6:51input, or if something only happens on
  174. 6:53an instance, that's why it's in here in
  175. 6:55update. And in our fixed update, we're
  176. 6:57going to add our move. So, physics are
  177. 6:59very good to do inside of the fixed
  178. 7:01update, so that's why we do our movement
  179. 7:03here. And for our late update, we'll do
  180. 7:05our position camera.
  181. 7:07This is quite important, or else our
  182. 7:09camera could look jittery, so it's good
  183. 7:11to put inside of the late update
  184. 7:13function. And that's everything for the
  185. 7:14script. Now, we just have to go back
  186. 7:16into Unity. In here, we'll click on the
  187. 7:17player and drag the third-person
  188. 7:19controller onto here. And now, we just
  189. 7:21need to set the camera, so drag the main
  190. 7:23camera onto here, and let's try to play.
  191. 7:26And yep, we can look around, we can walk
  192. 7:28around, and we can jump.
  193. 7:30And if you can't do any of that, and you
  194. 7:31have an error, maybe you're using the
  195. 7:33wrong input system. Just go to edit
  196. 7:34project settings, clear, scroll down,
  197. 7:35other settings, configuration, and set
  198. 7:36active input handling to both. If you
  199. 7:38found this video very useful, I know
  200. 7:39you'll like my school community, where
  201. 7:41my students go from a complete beginner
  202. 7:43all the way to publishing their own
  203. 7:45games. Check it out. That's the top link
  204. 7:47in the description. I really think
  205. 7:48you'll like it. We have a bunch of
  206. 7:50courses in there. You can get direct
  207. 7:52access to ask me any question anytime.
  208. 7:54[music] I'll literally be your direct
  209. 7:55mentor. So, check it out. Top link in
  210. 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.