Ok, firstly, I apologize for the title. I’ve found numerous similar posts about blueprints, but none that seem to answer my issue.
I am trying to create the ability for a user to use the mouse wheel to change how fast they’re walking. Scrolling up should increase, scrolling down should decrease. This is what I have:
In the character.h:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Speed Variables")
float MinimumSpeed;
UPROPERTY(EditAnywhere, BluePrintReadWrite, Category = "Speed Variables")
float MaximumSpeed;
private:
UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
bool bIncreasingSpeed;
UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
bool bDecreasingSpeed;
float MovementSpeed;
UPROPERTY(VisibleAnywhere, Category = "Speed Variables")
float VariableSpeed;
FVector MovementInput;
UCameraComponent* Camera;
void MoveForward(float AxisInput);
void MoveRight(float AxisInput);
void IncreaseSpeed();
void DecreaseSpeed();
The above is the declarations of my variables and methods. MinimunSpeed and MaximumSpeed are set in th editor so I can find the right speeds for my goal once this is working.
In the character.cpp:
void AStealthCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
InputComponent->BindAxis("MoveForward", this, &AStealthCharacter::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AStealthCharacter::MoveRight);
InputComponent->BindAxis("MouseTurn", this, &AStealthCharacter::AddControllerYawInput);
InputComponent->BindAxis("MouseLook", this, &AStealthCharacter::AddControllerPitchInput);
InputComponent->BindAction("IncreaseSpeed", IE_Pressed, this, &AStealthCharacter::IncreaseSpeed);
InputComponent->BindAction("DecreaseSpeed", IE_Pressed, this, &AStealthCharacter::DecreaseSpeed);
}
void AStealthCharacter::IncreaseSpeed()
{
if (!(VariableSpeed >= MaximumSpeed))
{
bIncreasingSpeed = true;
}
}
void AStealthCharacter::DecreaseSpeed()
{
if (VariableSpeed > MinimumSpeed)
{
bDecreasingSpeed = true;
}
}
void AStealthCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!MovementInput.IsZero())
{
MovementInput = MovementInput.GetSafeNormal() * 100.0f;
FVector NewLocation = GetActorLocation();
NewLocation += GetActorForwardVector() * MovementInput.X * DeltaTime;
NewLocation += GetActorRightVector() * MovementInput.Y * DeltaTime;
SetActorLocation(NewLocation);
}
if (bIncreasingSpeed)
{
VariableSpeed += MinimumSpeed + MinimumSpeed;
MovementSpeed = VariableSpeed;
bIncreasingSpeed = false;
}
if (bDecreasingSpeed)
{
VariableSpeed -= MinimumSpeed + MinimumSpeed;
MovementSpeed = VariableSpeed;
bDecreasingSpeed = false;
}
}
I’m setting the bools to true and if they’re true, in the tick they should increase/decrease the speed and then set the appropriate bool back to false. I tried this as a workaround after having the logic in the delegate wasn’t working. This isn’t working either. I made all of the values visible in the editor, and as far as I can tell, between that and setting breakpoints, my delegates don’t get called on scrolling and I can’t figure out why.