I am making a multiplayer game, where a main mechanic is the ability to dash towards the mouse. After quite a bit of pain, I have worked out all of the inputs. Now here’s the issue: I don’t know how to actually make the player dash. I have the button to start the dash, the timer for the dash, and the mouse/controller input set up. I know how to use things like “rb.velocity” or “rb.AddForce” But, I don’t know how to take my input’s Vector2 and actually apply it to the dash ability, to control the direction. Does anyone know how I might do this? Here’s the code I currently have:
public void Dash(InputAction.CallbackContext context)
{
// dash when dash button is pressed (dash button and the timer are handled in another void)
if (startDash == true)
{
Vector2 DashAim = context.ReadValue<Vector2>();
//dash
startDash = false;
}
}
I have it set to normalize the Vector2 inside of the input manager, so I won't need to do that in code. I'm just double checking to make sure I properly understand. It is 2D. I had written a little bit of code but checking it in the IDE i'm using showed it to have several errors. could you maybe give a code example of how I would do this in the context of what I have already?
– falconstrike209I have a physics material2D with 0 friction applied to the player, so it’s not that. The problem happens if I try to dash in midair as well. Although I think it’s because of the way I’m handling movement. In update I am constantly setting the velocity to input multiplied by move speed. I am going to change it so that that is only running if there is input.
– falconstrike209I will also make sure that it is disabled during the dash, so that it won’t interfere if dashing while holding the movement keys. Thank you for all the help!
– falconstrike209