- Home /
Modifying crouch script using Slerp
Hello, i've found a crouch script on the web that makes the player as it says crouch. It changes the character controller to adjust the crouch height and what not. But one thing that i get really annoyed at is that the player instantly crouches down, instead i would like so it takes some time for the player to crouch down. Im thinking that Slerp is the right method to use, but i need help because i dont really understand Slerp. How would you adjust the script?
Thanks (:
#pragma strict
private var crouchHeight : float;
private var standardHeight : float;
private var crouching : boolean = false;
private var controller : CharacterController;
private var mainCamera : GameObject;
function Start ()
{
controller = GetComponent(CharacterController);
mainCamera = gameObject.FindWithTag("MainCamera");
standardHeight = controller.height;
crouchHeight = controller.height/4;
crouching = false;
}
function Update () {
if (Input.GetKeyDown(KeyCode.LeftControl))
{
if(crouching)
{
controller.height = standardHeight ;
controller.center = Vector3 (0, 0, 0);
mainCamera.transform.localPosition.y += crouchHeight;
crouching = false;
return;
}
if(!crouching)
crouch();
}
}
function crouch() {
controller.height = crouchHeight;
controller.center = Vector3 (0, -0.5, 0);
mainCamera.transform.localPosition.y -= crouchHeight;
crouching = true;
}
Comment
Your answer
Follow this Question
Related Questions
My Player is going through the floor after crouching 0 Answers
Strange problem with crouch script 0 Answers
Making a cube crouch 1 Answer
crouch script problem 1 Answer