I’m trying to make a Parkour FPS, and I want the sliding to simply make the player shorter for 1 second, but I don’t know how to make the sliding last a definite n. of seconds.
This is the code of the whole script, the sliding code is the last part of the code:
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public float times = 6;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.C) )
{
controller.height = 2f;
Debug.Log(Time.time);
}
if (Time.time > times && Time.time < 6.1f)
{
controller.height = 3.8f;
}
}