Inconsistent acceleration

Hey

Ive been trying to copy the accelerate function from quake but I have a problem. The acceleration is very inconsistent, what I mean by that is that it seems to depend on my framerate. When my fps is uncapped i accelerate way faster compared to when i cap my fps to 60.

I have no clue why this is the case, the function gets called in the tick function inside CharacterMovementComponent. But I do multiply the added speed with delta seconds so it shouldnt matter.

void ABaseCharacter::StrafeAccelerate() { float currentSpeed, wishSpeed, addSpeed;
{
       FVector wishDir = GetCharacterMovement()->GetCurrentAcceleration().GetSafeNormal2D();
       currentSpeed = FVector::DotProduct(GetCharacterMovement()->Velocity, wishDir);
       addSpeed = GetCharacterMovement()->MaxWalkSpeed - currentSpeed;
       addSpeed = FMath::Max(FMath::Min(addSpeed, GetCharacterMovement()->MaxAcceleration * frameTime), 0.0f);
       GetCharacterMovement()->Velocity = GetCharacterMovement()->Velocity + (wishDir * addSpeed);
}

Assuming frameTime has the right value, the code seems correct. Have you tried to print the value of addSpeed when the game is running at 60fps against when it is running at 30fps? There should be a factor of two between the two values.

addSpeed after i have multiplied by frameTime?

The value of addSpeed after line 6.

60 fps :Screen capture - e75aa7d39265f8ea09c0a3a8e9cacaab - Gyazo

30 fps: Screen capture - 8ddde756bc7e6f848992fdb89bfd5be6 - Gyazo

Ok, the values seem right (34 cm/s against 68 cm/s) Could you do the same but on a straight line (without changing direction)? At some point we should see addSpeed settling to 0 (when acceleration equals 0).

30 fps: Screen capture - 479bdf8b2ea15bcfd93d891b86bdb170 - Gyazo

60 fps: Screen capture - f8600612569eb15a1998fec153b7f46f - Gyazo

Ok. Can I ask what value you set for MaxWalkSpeed variable?

919,171875

Ok, so according to your code it sould take around 0.43s to reach that speed (or 27frames @ 60fps and 13frames @ 30fps). Can you print addSpeed and GetCharacterMovement()->Velocity.Size() after line 7?

Tbh, I don’t see anything in your code that would explain your issue. That being said, I’m not sure it’s good practice to change the CharacterMovement’s velocity at each frame. I believe that what you’re trying to achieve would require to extend the CharacterMovementComponent class and override some base functions that handle the velocity in order to mimic Quake’s Character controller.

Well lets say that I want to keep using this function, how else would I call it? (instead of tick)

Also I want to add that i took the code from this guy.

He even says that it gets called on every frame :confused: