Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

inconsistent acceleration


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);

Product Version: UE 4.21
more ▼

asked Feb 23 '19 at 11:17 AM in C++ Programming

avatar image

3 1 2

avatar image Elou44 Feb 23 '19 at 04:39 PM

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.

avatar image filipanton Feb 23 '19 at 04:42 PM

addSpeed after i have multiplied by frameTime?

avatar image Elou44 Feb 23 '19 at 04:46 PM

The value of addSpeed after line 6.

avatar image filipanton Feb 23 '19 at 04:58 PM
avatar image Elou44 Feb 23 '19 at 05:22 PM

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).

avatar image filipanton Feb 23 '19 at 05:30 PM
avatar image Elou44 Feb 23 '19 at 05:38 PM

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

avatar image filipanton Feb 23 '19 at 05:41 PM


avatar image Elou44 Feb 23 '19 at 05:57 PM

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?

avatar image filipanton Feb 23 '19 at 06:03 PM
avatar image Elou44 Feb 23 '19 at 07:00 PM

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.

avatar image filipanton Feb 23 '19 at 07:03 PM

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

avatar image filipanton Feb 23 '19 at 07:19 PM

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


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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question