[solved?]Changing code to higher in script making it function properly but other things break...??

So i’m using the character controller and have set standards for when to apply gravity and normalized input into controller.move but since adding a new movement command I am getting stuff totally out of sync for some reason…

here’s what my code looks like for the two situations…

Void Update()
{
float yStore = moveDirection.y;
        moveDirection.y = yStore;
        moveDirection = (transform.forward * Input.GetAxis("Vertical") + (transform.right * Input.GetAxis("Horizontal")));
        moveDirection = moveDirection.normalized * moveSpeed;
        if (moveDirection.y > -20)
        {
            moveDirection.y += (Physics.gravity.y * Time.deltaTime * gravityScale);
        }
controller.Move(moveDirection * Time.deltaTime);
if (Input.GetKeyDown("d"))
{
ButtonCooler = 2.0f;       
ButtonCount += 1;
if (ButtonCount = 2)
{
moveDirection = transform.forward * rollDist * moveSpeed;
ButtonCount = 0;
}
}
}

now…
When I switched this last piece…

if (Input.GetKeyDown("d"))
{
ButtonCooler = 2.0f;       
ButtonCount += 1;
if (ButtonCount = 2)
{
moveDirection = transform.forward * rollDist * moveSpeed;
ButtonCount = 0;
}
}

to above the line…

controller.Move(moveDirection * Time.deltaTime);

this causes the transform forward to work but then breaks my gravity for some reason…

Please can you Help? I think this comes down to how I am ordering these operations and for some reason my brain isn’t clicking onto the “proper” order to do these functions.

I tried moving this d button piece around and it doesn’t change the fact that gravity remains broken, it actually causes more issues with movement…

Even just a general explanation on how the character controller is taking input on .move would help…
I have read this Unity - Scripting API: CharacterController.Move
but it doesn’t cover what i’m asking for or maybe i’m misunderstanding…

So I have no idea why this fixed my issue but in my infinite wisdom I had switched moveDirection.y = yStore; to above the moveDirection code when I also switched the “d” function under the assumption I was compact info together correctly…

my best guess is I was making moveDirection.y a value to be normalized even though I was trying to add to it after that fact???

I’m not even sure i’m 100% comprehending why this fixed my issue but hey… works now…