# Jittery movement

Video is attached at the bottom, but basically my character has jittery movement in all directions except forward. Left and right isn’t as bad as moving backwards, but it still happens, and obviously backwards is the worst. The only data member that is relevant here is this:

``````//Max skate speed (that can be achieved by just holding forward)
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Game Stats", meta = (AllowPrivateAccess = "true"))
float MaxPushSpeed;
``````

which gets defined in the constructor and set to a value, and then MaxPushSpeed is used to override the max walk speed from the movement component.

Basically what I have is this, MoveForward function is called in the SetupPlayerInputComponent method, and MoveForward looks like this:

``````void ASkater::MoveForward(float Value)
{
FVector velocity = this->GetVelocity();
float CurSpeed = velocity.Size();
if (CurSpeed < MaxPushSpeed && Value != 0)
{
float NewSpeed = CalculateSpeed(CurSpeed);
}
//Value == 0 taken into consideration so that if player will continue to move after letting go
//of input, which reflects how rollerskates behave in real life.
if (Value == 0)
{
float DotResult = (FVector::DotProduct(this->GetActorForwardVector(), velocity) / CurSpeed);
float NewSpeed = SlowDown(CurSpeed);
if (DotResult == 0)
{
return;
}
if (NewSpeed == 0.f)
{
CurSpeed = 0.f;
}
AddMovementInput(GetActorForwardVector(), DotResult * (NewSpeed - CurSpeed));
}
}
``````

And CalculateSpeed is defined as

``````float ASkater::CalculateSpeed(float CurSpeed)
{
float NewSpeed = 2 * FMath::Pow(CurSpeed, 2.f) + 1.f; // adding 1 bc if CurSpeed is 0, we'll never move
return FMath::Clamp(NewSpeed, 0.f, MaxPushSpeed);
}
``````

which is where the backwards jittery-ness is coming from, that or AddMovementInput.

I’ll also add the SlowDown method, as that appears to be when the Left/Right movement gets jittery

``````float ASkater::SlowDown(float CurSpeed)
{
CurSpeed -= 10.f;
return FMath::Clamp(CurSpeed, 0.f, MaxPushSpeed);
}
``````

These are really the only relevant methods. Video below, any help appreciated!