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. Dismiss Notice

Make player slide after releasing a key using a Character Controller (3D)

Discussion in 'Scripting' started by cgi2020, Feb 14, 2021.

  1. cgi2020

    cgi2020

    Joined:
    Aug 4, 2020
    Posts:
    3
    I'm using a character controller (i.e., Controller.Move). How do I make the player slide after I release the keyboard key that initiated the movement? Not looking for a solution based on RigidBody.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,723
    You'll have to do your own simulation of velocity. Keep track of the charcter's current velocity with a variable (Vector3 probably) and make it slowly go down to zero instead of instantly when the player releases the key. Something like:

    • If the player is holding the key, set velocity to max
    • If the player is not holding the key, reduce the velocity a bit each frame (deceleration)
    • Move the player based on the current velocity
     
    GroZZleR likes this.
  3. Vuile_rat

    Vuile_rat

    Joined:
    Feb 17, 2021
    Posts:
    1
    Do you have an answer, because I have the same problem
     
  4. cgi2020

    cgi2020

    Joined:
    Aug 4, 2020
    Posts:
    3
    No, sorry.