using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private Vector3 playerVelocity;
private bool isGrounded;
public float speed = 5f;
public float gravity = -9.8f;
public float jumpHeight = 3f;
public bool isSprinting = false;
public float sprintingMultiplier;
public bool lerpCrouch;
public bool crouching;
public float crouchTimer;
public bool sprinting;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
isGrounded = controller.isGrounded;
}
public void ProcessMove(Vector2 input)
{
Vector3 moveDirection = Vector3.zero;
moveDirection.x = input.x;
moveDirection.z = input.y;
controller.Move(transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
playerVelocity.y += gravity * Time.deltaTime;
if (isGrounded && playerVelocity.y < 0)
playerVelocity.y = -2f;
controller.Move(playerVelocity * Time.deltaTime);
Debug.Log(playerVelocity.y);
}
public void Jump()
{
playerVelocity.y = Mathf.Sqrt(jumpHeight * -1.0f * gravity);
}
void Update()
{
isGrounded = controller.isGrounded;
if (lerpCrouch)
{
crouchTimer += Time.deltaTime;
float p = crouchTimer / 1;
p *= p;
if (crouching)
{
controller.height = Mathf.Lerp(controller.height, 1, p);
}
else
{
controller.height = Mathf.Lerp(controller.height, 1, p);
}
if (p > 1)
{
lerpCrouch = false;
crouchTimer = 0f;
}
}
}
public void Crouch()
{
crouching = !crouching;
crouchTimer = 0;
lerpCrouch = true;
if (crouching)
{
speed = 3;
}
else
{
speed = 5;
}
}
public void Sprint()
{
sprinting = !sprinting;
if (sprinting)
{
speed = 8;
}
else
{
speed = 5;
}
}
}***