Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Vector3 moveDirection;
- public const float maxDashTime = 1.0f;
- public float dashDistance = 10;
- public float dashStoppingSpeed = 0.1f;
- float currentDashTime = maxDashTime;
- public float dashSpeed = 4;
- CharacterController controller;
- public bool isDashing;
- public bool canDash;
- private void Awake()
- {
- controller = GetComponent<CharacterController>();
- }
- void Update()
- {
- if (controller.isGrounded == true)
- {
- canDash = true;
- isDashing = false;
- }
- if (canDash == true && Input.GetKeyDown(KeyCode.R) && controller.isGrounded == false)
- {
- currentDashTime = 0;
- isDashing = true;
- canDash = false;
- FindObjectOfType<SoundController>().dashingSound.Play();
- }
- if (currentDashTime < maxDashTime)
- {
- moveDirection = transform.forward * dashDistance;
- currentDashTime += dashStoppingSpeed;
- }
- else
- {
- moveDirection = Vector3.zero;
- }
- controller.Move(moveDirection * Time.deltaTime * dashSpeed);
- }
Advertisement
Add Comment
Please, Sign In to add comment