Forum begins after the advertisement:

 


[Part 2] No Response with Dashing

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 2] No Response with Dashing

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #17880
    Doctor Frostbloom
    Level 4
    Participant
    Helpful?
    Up
    0
    ::

    I’ve ran into a unique issue in which the character cannot dash, as if no code exists for it in the database. I’ve fixed it as best as I can (I even got a NullReferenceException at one point but it was because I missed a code string and now the character works again), but now not a single coding response happens. All the code for the dashing has been implemented, the character has no irregularities with movement, the keybind for dashing has been set, but no dash happens. Here’s the .zip for my game in case it’s needed since that might be the only way to solve this (I genuinely don’t know where the problem is, code seems fine as does the projectsettings): https://drive.google.com/drive/folders/102fp9N7NNH6vljSeoOXC2fti674eaqKZ?usp=sharing Please help me with this so I can not only learn from it but also continue my programming adventure.

    #17881
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    You are unable to dash because in your PMovement script, the canDash variable is never initialised. This means that it is false by default. Initialise it to true by default.

    [Header("Dash Settings")]
    [SerializeField] private float dashSpeed;
    [SerializeField] private float dashTime;
    [SerializeField] private float dashCooldown;
    [Space(5)]
    
    PlayerStates pState;
    private float xAxis;
    private float gravity;
    private Rigidbody2D rb;
    Animator anim;
    private bool canDash = true;
    private bool dashed;

    Otherwise your dash condition never gets fulfilled:

    void StartDash()
    {
        if(Input.GetButtonDown("Dash") && canDash && !dashed)
        {
            StartCoroutine(Dash());
            dashed = true;
        }
    
        if (Grounded())
        {
            dashed = false;
        }
    }

    In future, paste the codes you think have issues here so I can have a look at the code directly. It is not very convenient for me to open your project every time you run into an issue.

    #17892
    Doctor Frostbloom
    Level 4
    Participant
    Helpful?
    Up
    1
    ::

    Ah, thank you so much! Sorry for not uploading the code, I just didn’t know where the issue was so I wanted to cover all the bases in case it wasn’t a code problem and a settings problem. But it was a code problem, so I’ll make sure that if I run into more issues, I’ll post the code first! Thank you again so much for helping me with this!

    has upvoted this post.
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: