Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

I'm trying to make my player "Dash" but seems like it got stuck in place. pls help. Code below

Discussion in 'Scripting' started by slippersandsocks, Apr 18, 2020.

  1. slippersandsocks

    slippersandsocks

    Joined:
    Jan 31, 2020
    Posts:
    84
    Code (CSharp):
    1.  void Movement()    //For movementInput as Rigidbody
    2.     {
    3.         float MoveInputX = Input.GetAxisRaw("Horizontal");
    4.         float MoveInputZ = Input.GetAxisRaw("Vertical");
    5.  
    6.         Vector3 MoveVelocity = new Vector3(MoveInputX, 0, MoveInputZ);
    7.         MoveVelocity = MoveVelocity.normalized * moveSpeed * Time.deltaTime;
    8.         rb.MovePosition(transform.position + MoveVelocity);
    9.     }
    10.  
    11.     void Dashing()
    12.     {
    13.         if (Input.GetKeyDown(KeyCode.Space))
    14.         {
    15.             currentDashTime = 0.0f;
    16.         }
    17.  
    18.         if (currentDashTime < maxDashTime)
    19.         {
    20.             moveDirection = new Vector3(0, 0, dashSpeed);
    21.             currentDashTime += dashStopSpeed;
    22.         }
    23.  
    24.         else
    25.         {
    26.             moveDirection = Vector3.zero;
    27.         }
    28.  
    29.         rb.MovePosition(moveDirection * Time.deltaTime);
    30.     }
     
  2. SpartianTheDev

    SpartianTheDev

    Joined:
    Jan 17, 2019
    Posts:
    11
    What is dashstopspeed related to?
    I think there must be a Time.deltatime somewhere with increasing currentDashTime