Announcement

Collapse
No announcement yet.

UE4 Sprint jitter.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    UE4 Sprint jitter.

    I have this function to handle sprinting:
    Code:
    void ADynamixCPPCharacter::StartSprint_Implementation()
    {
    sprinting = !sprinting;
    if (sprinting) {
    GetCharacterMovement()->MaxWalkSpeed = 3000;
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Sprint"));
    }
    else {
    GetCharacterMovement()->MaxWalkSpeed = baseWalkSpeed;
    GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Stop Sprint"));
    }
    }
    When I sprint in the game, and when connected to a server, it jitters. Using (basically) the same code in blueprints does not have this effect. It is replicated to the server, Unreliably.

    What am I doing wrong?

    Here is the UFUNCTION definition:
    Code:
    UFUNCTION(Uneliable, Server, WithValidation)
    void StartSprint();
    void StartSprint_Implementation();
    bool StartSprint_Validate();
    StartSprint_Validate jsut returns true
    and the input action that it is bound to:

    Code:
    PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &ADynamixCPPCharacter::StartSprint);
    My unreal engine version is 4.25
    Last edited by OuchImBad; 05-21-2020, 06:38 PM.

    #2
    Well without seeing more of how this is working I can only guess. In general I have found that movement "Jitters" are almost always a difference in velocity between the server and the client. If this function is fired only once (say button pressed event) and replicates "unreliably" that could be a problem in itself, but if that function is fired on tick than the unreliable tag is appropriate (Never run reliable functions on tick, and only ever try to have at most one unreliable RPC on tick). Generally all my to server RPCs that handle input are reliable (except for the ones that continuously fire of course).
    Last edited by ArcainOne; 05-21-2020, 02:24 PM.
    Professional Game Developer
    Asadeus Studios

    Marketplace Content:
    Pro Mounting System

    Comment


      #3
      Sorry for not including it but here is the InputAction bound to it:

      Code:
      PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &ADynamixCPPCharacter::StartSprint);
      I just tried to set it to Reliable, and it makes no difference.

      The only other part pertaining to this function is in the .h file:
      Code:
      UFUNCTION(Unreliable, Server, WithValidation)
      void StartSprint();
      void StartSprint_Implementation();
      bool StartSprint_Validate();
      StartSprint_Validate jsut returns true

      Thanks for your reply.
      Last edited by OuchImBad; 05-21-2020, 06:38 PM.

      Comment


        #4
        The jittering you are experiencing comes from the network corrections the MovementComponent on your Character performs automatically.

        Like all other MovementTypes (Jumping, Crouching, etc.) sprinting should also be implemented using the MovementComponent, you can find tutorials on how to do this correctly here:

        https://docs.unrealengine.com/en-US/...ent/index.html

        https://michaeljcole.github.io/wiki....cter_Movement/

        Comment


          #5
          Originally posted by Elyy View Post
          The jittering you are experiencing comes from the network corrections the MovementComponent on your Character performs automatically.

          Like all other MovementTypes (Jumping, Crouching, etc.) sprinting should also be implemented using the MovementComponent, you can find tutorials on how to do this correctly here:

          https://docs.unrealengine.com/en-US/...ent/index.html

          https://michaeljcole.github.io/wiki....cter_Movement/
          +1 on this. This is exactly what came to my mind when I read the OP.
          Check out this open source New C++ Module tool on the Marketplace and the forums

          Comment


            #6
            Thank you for your answers! I am going to try Elyy 's answer as soon as I can.

            Comment

            Working...
            X