I’m trying to make a simple 3rd person RPG and want the character to be able to do a roll to dodge. Right now it just makes it impossible to walk in the opposite direction after hitting Shift-W. My current code is this:
public class Roll : MonoBehaviour { public float testStamina = 100.0f; public float coolDown = 2.0f; public float rollLength = 5.0f; public float lastRoll; public float rollDuration = 2.0f; public float startTime; bool canRoll; // Use this for initialization void Start () { lastRoll = Time.time; canRoll = true; } // Update is called once per frame void Update () { if(coolDown >= Time.time - lastRoll) canRoll = true; if(Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift) && canRoll == true){ canRoll = false; startTime = Time.time; if(startTime - rollDuration <= Time.time){ rigidbody.AddForce(Vector3.forward * -100f); } lastRoll = Time.time; } } } ` I feel like its something I should really know how to do, but its 2 in the morning and I need to finish this. Any help is greatly appreciated. `