Please, next time use code tags, it will be much easier for everyone to read.
I see that you are beginner and don’t really know what tthis whole code means so I think you don’t need to use Assets that are meant for complex applications. I think you should remove Cinemachine and first understand Unity’s main camera. If you want to use 3rd person camera movement, watch this video, it’s really easy to understand:
and this for 1st person movement:
But to answer your question, I will share you my(actually 95% is by Brackeys) primitive code for sprinting
using UnityEngine;
public class Movement : MonoBehaviour
{
public CharacterController Player;
public float speed = 12f;
public float sprintSpeed = 24f;
public float jumpHeight = 0.5f;
public Transform groundCheck;
public float groundDistance = 0.7f;
public LayerMask groundMask;
public float gravity = -9.81f;
public Camera myCam;
Vector3 velocity;
bool isGrounded;
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float z = Input.GetAxis("Vertical");
float x = Input.GetAxis("Horizontal");
Vector3 move = transform.right * x + transform.forward * z;
if(Input.GetKey("left shift"))
{
Player.Move(move * sprintSpeed * Time.deltaTime);
myCam.fieldOfView += 0.2f;
if(myCam.fieldOfView >= 70)
{
myCam.fieldOfView = 70;
}
}
else
{
Player.Move(move * speed * Time.deltaTime);
myCam.fieldOfView -= 0.2f;
if (myCam.fieldOfView <= 60)
{
myCam.fieldOfView = 60;
}
}
if(isGrounded && Input.GetButton("Jump"))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
}
velocity.y += gravity * Time.deltaTime;
Player.Move(velocity * Time.deltaTime);
}
}
This is whole code for 1st person movement, spriniting and jumping
If you want just the code for sprinting:
if(Input.GetKey("left shift"))
{
Player.Move(move * sprintSpeed * Time.deltaTime);
myCam.fieldOfView += 0.2f;
if(myCam.fieldOfView >= 70)
{
myCam.fieldOfView = 70;
}
}
else
{
Player.Move(move * speed * Time.deltaTime);
myCam.fieldOfView -= 0.2f;
if (myCam.fieldOfView <= 60)
{
myCam.fieldOfView = 60;
}
}
There’s added an effect which raise the FOV when sprinting (just like in minecraft)