Hi there, I’m having some trouble implementing a “dash” move for my rigidbody player controller. I’ve tried a handful of methods and other posted solutions, but I think I’m getting a bit jumbled up between the inputs, Update vs fixedUpdate, using speed and time.(fixed)deltaTime, and the movement system I’m using.
I’m building off of the character controller made by MinionsArt, where movement is controlled by setting rb.velocity directly inside FixedUpdate. I don’t think this is having an effect on the move I’m trying to create, but I figured I’d mention it just in case.
Anyway, what I’m trying to implement is this: when the player holds down the dash key (F) it will show you the final landing location based on your current direction and you will dash to it upon releasing the key.
private void FixedUpdate()
{
dashLocation = transform.position + transform.forward * dashDistance;
if (Input.GetKeyUp(KeyCode.F))
{
Dash();
Debug.Log("Dashing.");
}
}
private void Dash()
{
//rb.AddForce(transform.forward * dashAmount, ForceMode.Impulse);
//rb.MovePosition(Vector3.SmoothDamp(transform.position, dashLocation, ref velocity, 1f));
rb.MovePosition(dashLocation);
}
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
if (Input.GetKey(KeyCode.F))
{
Gizmos.DrawWireSphere(dashLocation, 0.3f);
}
}
Right now, just using rb.MovePosition(dashLocation) is the only thing that slightly works. It moves my rigidbody to the correct place instantaneously. The other two lines I have inside my dash function either only move a tiny bit, or don’t move. However, what I want is for the rigidbody to move to the desired location smoothly over time (ideally a fast time to create a dash effect), or even with a bit of easing in and out at the start and end of the movement. Whenever I try adding any time of deltaTime or fixedDeltaTime * speed, it either barely moves, or completely overshoots the location.
Also, I’m a bit confused about handling inputs and rigidbody movements and what functions to put them in. I know rb physics should go in FixedUpdate, but putting any inputs in fixedUpdate means they don’t always get called when the player presses a button. And what about when all of the implementation exists in a separate function like my Dash() function? Any tips on the best way to handle that?
Any help is greatly appreciated. Thank you!