I recently made a dash ability that dashes towards the mouse, using the new input system. I want this ability to also work if using a controller, by reading the direction the knob is being pushed and using that for the direction of the dash. Does anyone know how I can set it up so that the direction the knob is being pressed works like the direction to the mouse from the player?
I had tried this setup:
but when dashing on the controller it would ignore the direction I was pressing the knob, and just dash downwards diagonally to the left, regardless of the mouse’s position even. The part of the script I am using to read the input and dash looks like this:
public void Dash(InputAction.CallbackContext context)
{
Vector2 dashAim = context.ReadValue<Vector2>();
Vector3 dashAim3 = dashAim;
Vector3 dashDir3 = (dashAim3 - camera.WorldToScreenPoint(rb.transform.position)).normalized;
Vector2 dashDir = new Vector2(dashDir3.x, dashDir3.y);
//if button has been pressed
if (startDash == true)
{
//dash
rb.velocity = dashDir * dashSpeed;
cantAirJump = true;
startDash = false;
}
}