Crouching/crawling functionality is working
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Collections;
|
|||||||
public class PlayerController : MonoBehaviour
|
public class PlayerController : MonoBehaviour
|
||||||
{
|
{
|
||||||
CharacterController characterController;
|
CharacterController characterController;
|
||||||
|
CapsuleCollider capsule;
|
||||||
|
|
||||||
public float speed;
|
public float speed;
|
||||||
public float jumpHeight;
|
public float jumpHeight;
|
||||||
@@ -19,11 +20,18 @@ public class PlayerController : MonoBehaviour
|
|||||||
public GameObject playerModel;
|
public GameObject playerModel;
|
||||||
|
|
||||||
private int jump = 0;
|
private int jump = 0;
|
||||||
|
private float capsuleHeight;
|
||||||
|
private float controllerHeight;
|
||||||
|
private float transformHeight;
|
||||||
private Vector3 moveDirection;
|
private Vector3 moveDirection;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
characterController = GetComponent<CharacterController>();
|
characterController = GetComponent<CharacterController>();
|
||||||
|
capsule = GetComponent<CapsuleCollider>();
|
||||||
|
transformHeight = transform.localScale.y;
|
||||||
|
controllerHeight = characterController.height;
|
||||||
|
capsuleHeight = capsule.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
@@ -55,6 +63,19 @@ public class PlayerController : MonoBehaviour
|
|||||||
moveDirection = moveDirection.normalized * speed;
|
moveDirection = moveDirection.normalized * speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Input.GetKey(KeyCode.LeftControl))
|
||||||
|
{
|
||||||
|
moveDirection = (moveDirection.normalized * speed/4);
|
||||||
|
characterController.height /= 2;
|
||||||
|
capsule.height /= 2;
|
||||||
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
|
||||||
|
} else {
|
||||||
|
moveDirection = moveDirection.normalized * speed;
|
||||||
|
characterController.height = controllerHeight;
|
||||||
|
capsule.height = capsuleHeight;
|
||||||
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.GetButtonDown("Jump") && jump <= 1)
|
if (Input.GetButtonDown("Jump") && jump <= 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user