
PlayerCameraParent.localRotation = Quaternion.Euler(rotation.x, 0, 0) Rotation.x = Mathf.Clamp(rotation.x, -lookXLimit, lookXLimit) Rotation.x += -Input.GetAxis("Mouse Y") * lookSpeed Rotation.y += Input.GetAxis("Mouse X") * lookSpeed
MoveDirection.y -= gravity * ltaTime ĬharacterController.Move(moveDirection * ltaTime) This is because gravity should be applied when the moveDirection is multiplied by deltaTime). Gravity is multiplied by deltaTime twice (once here, and once below MoveDirection = (forward * curSpeedX) + (right * curSpeedY) Vector3 right = transform.TransformDirection(Vector3.right) įloat curSpeedX = canMove ? speed * Input.GetAxis("Vertical") : 0 įloat curSpeedY = canMove ? speed * Input.GetAxis("Horizontal") : 0 Vector3 forward = transform.TransformDirection(Vector3.forward) We are grounded, so recalculate move direction based on axes Public class SC_TPSController : MonoBehaviour
Create a new Script and call it SC_TPSController and paste the code below inside it:. Move the Main Camera inside "CameraParent" Object and move it behind the Player (In my case I moved it to this position: (0.5, 0.6, -2.9)). Create a new GameObject and name it "CameraParent" and move it inside "Player" Object, change its position to (0, 1.64, 0).
Remove Capsule Collider component from Capsule and change its position to (0, 1, 0).
Create new Capsule (Game Object -> 3D Object -> Capsule) and move it inside "Player" Object. Create a new Game Object (Game Object -> Create Empty) and name it "Player". To make a Third-Person Shooter (TPS) camera in Unity we will use a combination of a regular player movement and a third-person view.įirst, we will create a Player controller that will handle rotation and movement: You can also (), so if you want to help with anything, feel free to fork the project, make changes and create a pull request when you're done.A Third-Person camera is a type of camera placed behind the player, usually slightly shifted to the side, giving a visual representation of the game level and the player itself. Includes an optional "Immersive First Person" mode and keybinds for switching between camera modes and for flipping the camera side. You can switch between first and third person at will and all the camera settings can be adjusted in the mod options menu. This mod lets you play the game in third person mode.