jretchy

Untitled

May 16th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. public Vector3 moveDirection;
  2.  
  3.     public const float maxDashTime = 1.0f;
  4.     public float dashDistance = 10;
  5.     public float dashStoppingSpeed = 0.1f;
  6.     float currentDashTime = maxDashTime;
  7.     public float dashSpeed = 4;
  8.     CharacterController controller;
  9.  
  10.     public bool isDashing;
  11.     public bool canDash;
  12.  
  13.  
  14.  
  15.     private void Awake()
  16.     {
  17.         controller = GetComponent<CharacterController>();
  18.     }
  19.  
  20.     void Update()
  21.     {
  22.  
  23.         if (controller.isGrounded == true)
  24.         {
  25.             canDash = true;
  26.             isDashing = false;
  27.         }
  28.  
  29.  
  30.         if (canDash == true && Input.GetKeyDown(KeyCode.R) && controller.isGrounded == false)
  31.         {
  32.             currentDashTime = 0;
  33.             isDashing = true;
  34.             canDash = false;
  35.  
  36.             FindObjectOfType<SoundController>().dashingSound.Play();
  37.            
  38.            
  39.         }
  40.             if (currentDashTime < maxDashTime)
  41.             {
  42.                 moveDirection = transform.forward * dashDistance;
  43.                 currentDashTime += dashStoppingSpeed;
  44.             }
  45.             else
  46.             {
  47.                 moveDirection = Vector3.zero;
  48.             }
  49.             controller.Move(moveDirection * Time.deltaTime * dashSpeed);
  50.     }
  51.            
  52.  
Advertisement
Add Comment
Please, Sign In to add comment