Currently, I have this blueprint connected to the move and stop pin.
So I thought I’d write the function twice to get the Move and Stop conditions. The StopZipline event should be triggered when I press a certain key. However, it can only occur when the Move section has finished.
I have the impression that with MoveComponentTo you can only set one “MoveAction” parameter. Wouldn’t there be a way to merge the 2 lines into one, like with the blueprint?
(Simplified code below)
void UZiplineComponent::UseZipline()
{
if (Cast<APlayerController>(PlayerCharacter->GetController())->WasInputKeyJustPressed(EKeys::E)) {
PlayerCharacter->GetCharacterMovement()->SetMovementMode(MOVE_Flying);
FLatentActionInfo LatentInfo;
LatentInfo.CallbackTarget = this;
LatentInfo.ExecutionFunction = FName("MoveToTargetFinished");
LatentInfo.Linkage = 0;
LatentInfo.UUID = 0;
FLatentActionInfo StopCondition;
StopCondition.CallbackTarget = this;
StopCondition.ExecutionFunction = "StopZipline";
StopCondition.Linkage = 0;
StopCondition.UUID = 1;
UKismetSystemLibrary::MoveComponentTo(PlayerCharacter->GetCapsuleComponent(), RelativeLocation, RelativeRotation,
false, false, OverTime, true, EMoveComponentAction::Move, LatentInfo);
UKismetSystemLibrary::MoveComponentTo(PlayerCharacter->GetCapsuleComponent(), RelativeLocation, RelativeRotation,
false, false, OverTime, true, EMoveComponentAction::Stop, StopCondition);
}
}
}
void UZiplineComponent::JumpDuringZipline()
{ if (Cast<APlayerController>(PlayerCharacter->GetController())->WasInputKeyJustPressed(EKeys::SpaceBar)) { if (!PlayerCharacter->GetCharacterMovement()->IsFalling() && bOnZipline) { StopZipline();
UKismetSystemLibrary::RetriggerableDelay(this, 0.0001, FLatentActionInfo{});
PlayerCharacter->GetCharacterMovement()->SetMovementMode(MOVE_Falling);
//Changer les valeur pour controler la vitesse du saut
const FVector Velocity = PlayerCharacter->GetActorForwardVector() * 2500 + PlayerCharacter->GetActorUpVector() * 900.f;
PlayerCharacter->LaunchCharacter(Velocity, true, true);
}
}
}
void UZiplineComponent::MoveToTargetFinished()
{
PlayerCharacter->GetCharacterMovement()->SetMovementMode(MOVE_Walking);
UKismetSystemLibrary::K2_ClearAndInvalidateTimerHandle(this, Timer);
bOnZipline = false;
}
void UZiplineComponent::StopZipline()
{ UE_LOG(LogTemp, Warning, TEXT("Stop Zipline")); }
void UZiplineComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{ Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
UseZipline();
JumpDuringZipline();
}