← Back to all addons

PlayerController Built-in Dash

Posted by Gyvr on May 8, 2024 at 3:42 PM

GameplayFeature1.3 Verified
πŸ’‘ 6 πŸ’› 2 πŸ’― 2 πŸ”₯ 2

This add-on updates the dash ability by integrating it directly into the PlayerController code, allowing players to dash without needing to equip a specific ability!

PlayerController.cs (line 17 to 21):

[Header("Dash")]
[SerializeField][Min(0)] private float m_dashStrength = 1;
[SerializeField][Min(0)] private float m_dashResistance = 1;
[SerializeField] private ParticleSystem m_dashParticleSystem = null;

PlayerController.cs (line 50):

GameManager.InputSystem.gameplay.dash.performed += OnDash;

PlayerController.cs (line 62):

GameManager.InputSystem.gameplay.dash.performed -= OnDash;

PlayerController.cs (line 143 to 156):

private void OnDash(InputAction.CallbackContext context)
{
    Vector2 direction =
        m_character.IsMoving() ?
        m_character.movementDirection :
        (m_character.GetLookAtDirection() == EDirection.Right ? Vector2.right : Vector2.left);

    m_character.Push(direction, m_dashStrength, m_dashResistance, faceOppositeDirection: true);
    if (m_dashParticleSystem != null)
    {
        m_dashParticleSystem.Play();
    }
}
// Line break so it looks nicer :)

InputSystem.cs (line 10):

public InputAction dash;

InputSystem.cs (line 81):

dash = actions.FindAction("Dash"),

Usage:

  1. Open Dash.prefab
  2. Copy the Particle System component
  3. Open 0_Hero_Base.prefab
  4. Create a child Game Object to the base
  5. Paste the Particle System component in this new Game Object
  6. Select the root (0_Hero_Base)
  7. Scroll down to Player Controller, and set the dash strength and resistance (18 and 12 work well for me)
  8. Set the Dash Particle System reference by drag-and-dropping the Game Object you just created in the field
  9. Open PlayerInputActions.inputactions
  10. Duplicate the “Interact” action in the Gameplay map
  11. Rename it to “Dash”
  12. Update its bound keys (Keyboard & Gamepad)
  13. Save the asset

PlayerController Built-in Dash

πŸ’¬ Comments (15)

SvanDark Jan 11, 2025 at 11:36 PM
Heyo, i’ve been trying to make this work, however when i’m modifying the PlayerController script i keep getting those 2 errors, even tho i’ve doubled checked and nothing seems to be wrong, if needed i can share my code and maybe you can see if i actually did a mistake or not
Gyvr Jan 12, 2025 at 01:20 AM
You’re missing a semicolon 😊
SvanDark Jan 12, 2025 at 01:22 AM

No the semicolon is actually there tho (on the line it says where the error is) πŸ€”

Want me to send the code over, or? I could be wrong obviously but i believe it’s there

Gyvr Jan 12, 2025 at 01:22 AM
Look on the line right before the line mentioned in the error message
SvanDark Jan 12, 2025 at 01:22 AM
Sure, give me a minute
SvanDark Jan 12, 2025 at 01:35 AM

Doesn’t seem to be that, this is how the lines look

and even if i give line 81 a semicolon instead of “,” i get more erros (shown on the third pic)

Gyvr Jan 12, 2025 at 01:43 AM
I’m very confused about why you have dash = actions.FindAction("Dash"), inside of the PlayerController.cs class. If you follow the instruction, this line should be added to InputSystem.cs (line 81)
SvanDark Jan 12, 2025 at 01:45 AM
oh hold up, i completely missed that, sorry about that
πŸ‘Œ 1
SvanDark Jan 12, 2025 at 01:51 AM
also one more thing, when you say “Create a child Game Object to the base”, do you mean like this? πŸ€”
SvanDark Jan 12, 2025 at 01:51 AM
just making sure
Gyvr Jan 12, 2025 at 01:51 AM
No, it’s inside of 0_Hero_Base.prefab
SvanDark Jan 12, 2025 at 01:54 AM
oh wait i’m pepega, tyvm!
🫑 1
Mr.Titan Jan 14, 2025 at 06:48 PM
Just noticed, when we dash agains a static object “tree” for example, we get stucked.
Gyvr Jan 14, 2025 at 07:00 PM
Yeah… I’ll try to get something for this one for the next update

Want to continue the conversation?