I just got my dash mechanic working in my test game (with some help on this forum), however it does not work 100% of the time. When I press my input of space, my player should dash forward in the direction they are facing at the time and print to the console “Dashing”. What I am experiencing is some major inconsistency with this. Sometimes neither the dash or the console message will occur, others times only one or the other will happen, and occasionally both will work as I would expect.
Everything I have been reading regarding similar issues, the person had their code in the FixedUpdate method and moving it to the regular Update method fixed their problem. I have tried my code in the Update method and (as my script below shows) tried calling my script from another method to the Update. I experience the same results regardless of which method I use. I also tried creating a separate script for my Dash, but that resulted in no movement at all from my current script (with a few adjustments).
Is there something I am doing wrong on my part or am I misunderstanding how the Update method works?
I could be wrong but I think in Time.DeltaTime 1000.0f == 1 second, so where you’ve set dashTime to 0.25f, that might be expiring instantly. I could be mistaken.
Also, just quickly, really awesome thing you can do is use conditional operators. Cuts down on rewriting the same code.
Anyhoo, I’ve very little experience using rigidbodies but if you’re changing the velocity, doesn’t that mean that at some point it should be normalised?
Thanks again for replying Thimble! Conditional operators seem very handy and I’ll be looking for more areas to implement that in the future. Regarding the dashTime, it’s actually dashTimer which I use to limit how often the player can dash (or I guess teleport is more accurate because you really can’t see any acceleration, he just instantly blinks forwards for the dashDistance). I’m not sure what you mean by normalizing the velocity, but I can dash while standing still and will remain standing still or do it while moving and I will quickly move the dashDistance and then continue at my regular speed.
After altering my script a bit with the new conditional operators and messing around with Time.deltaTime I was still experiencing the same issue of inconsistently being able to dash, however after trying the .AddRelativeForce you linked I managed to get it working 100% of the time. It doesn’t feel as smooth but I’m sure after some tweaking I’ll get it just right!
Thanks again for you help, I can finally move forward with my project now that I’ve finished the basic movement systems I want to use. Is there a way I can upvote you or anything?