The problem here is fairly straightforward:
You’re pre-calculating a value which doesn’t need to be calculated ahead of time, and multiplying it by the wrong value at the wrong time.
moveSpeed is your value for your current speed, which you’re feeding into your Rigidbody’s Velocity as movementSpeed. Additionally, Update() really isn’t the ideal place to update Rigidbody data, because the results won’t have the timing you intend for them.
Based on the multiplication you’re applying, I will assume (for the purposes of this answer) that you want moveSpeed to increase by 0.05 per second rather than 0.05 per frame.
With this in mind, I propose the following:
// If desired, allow the maximum speed to be adjusted. This may help in numerous ways in the long term.
public float maximumSpeed = 19.0f;
// Acceleration per second
public float accPerSec = 0.05f;
Rigidbody rb;
void Start()
{
moveSpeed = 4.0f;
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(moveSpeed < maximumSpeed)
{
moveSpeed += accPerSec * Time.deltaTime;
if(moveSpeed > maximumSpeed)
{
moveSpeed = maximumSpeed;
}
}
}
void FixedUpdate()
{
rb.velocity = new Vector3(horizVel, 0, moveSpeed);
}
First, I combined a few values. By moving the Time.deltaTime multiplication and setting a starting value of 4 to moveSpeed, I cut out the transformations that were applied and eliminated the need for the movementSpeed variable.
Second, now that the moveSpeed increases are no longer a consistent value, I put a check inside the initial if statement to check if you went over the maximum, so that it will only be checked whenever the speed does increase.
Finally, I moved the Rigidbody calls into their own variable, since that improves efficiency considerably compared to calling GetComponent<> every frame. Then, by moving the velocity changes into FixedUpdate(), they only get called on a Physics frame, rather than attempting to change velocity during every rendering frame, which may be faster or slower than the physics updates are being performed.