- Home /
Why does my player dash differently based on window size?
So I have been working on a dash for my third person game. The dash looks amazing and I have already fine-tuned the values for the perfect dash distance, but I noticed that the dash is different based on window size. For example, if my window isn't full screen, the dash is about 10 blocks/units. But as soon as I make the game full screen and dash, the player dashes about 30-40 blocks/units. It really makes it difficult and I can't seem to figure out why it does that. Any help? The dash code looks something like this
IEnumerator dashmoveforward(Vector3 movedirection) {
float startTime = Time.time;
while (Time.time < startTime + dashtime) {
controller.Move(movedirection * dashstrength);
yield return null;
}
}
Answer by Eno-Khaon · Nov 01, 2021 at 08:37 AM
CharacterController.Move() functions on the basis of position changes with each call. This means that in order to use it properly to make it framerate-independent, you want to multiply the value contained in it by Time.deltaTime.
With that in mind, there's something to be considered:
First, if you're moving 3-4 times as far, then your framerate is 3-4 times higher as well. This could mean that vertical sync is on when windowed and off when fullscreen, or maybe your framerate's lousy windowed. Either way, that framerate dependence is why the distance varies.
Luckily, this should be easy enough to deal with. Multiply your "dashstrength" value by your windowed framerate (60 or similar common refresh rate, hopefully?) and you should be good to go:
controller.Move(movedirection * dashstrength * Time.deltaTime);
Your answer
Follow this Question
Related Questions
,I am trying to code a dash in c#. I cant get it, help! 1 Answer
Dash in the direction of a parents child object 1 Answer
Trying to Dash Using Standard Third Person Controller 0 Answers
How to do a "dash"-movement, set distance on key-input? 0 Answers
Dash in movement direction, not in forward direction 0 Answers