diff --git a/Content/BP_BugPlacerPawn.uasset b/Content/BP_BugPlacerPawn.uasset index d72dd92..a734552 100644 Binary files a/Content/BP_BugPlacerPawn.uasset and b/Content/BP_BugPlacerPawn.uasset differ diff --git a/Source/Unrealzilla/Private/BugPlacerPawn.cpp b/Source/Unrealzilla/Private/BugPlacerPawn.cpp index 6a3a018..0ae00b7 100644 --- a/Source/Unrealzilla/Private/BugPlacerPawn.cpp +++ b/Source/Unrealzilla/Private/BugPlacerPawn.cpp @@ -3,7 +3,9 @@ #include "BugPlacerPawn.h" #include "Components/SphereComponent.h" +#include "GameFramework/Character.h" #include "GameFramework/FloatingPawnMovement.h" +#include "Kismet/GameplayStatics.h" ABugPlacerPawn::ABugPlacerPawn() @@ -27,10 +29,14 @@ ABugPlacerPawn::ABugPlacerPawn() void ABugPlacerPawn::BeginPlay() { - Super::BeginPlay(); - this->GetWorldSettings()->SetTimeDilation(this->GetWorldSettings()->MinGlobalTimeDilation); this->CustomTimeDilation = 1.0f / this->GetWorldSettings()->MinGlobalTimeDilation; + + this->OriginalPlayer = UGameplayStatics::GetPlayerCharacter(this, 0); + + this->Activate(); + + Super::BeginPlay(); } void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) @@ -40,3 +46,18 @@ void ABugPlacerPawn::EndPlay(const EEndPlayReason::Type EndPlayReason) Super::EndPlay(EndPlayReason); } + + +void ABugPlacerPawn::Activate() +{ + this->SavedMaxSpeed = this->PawnMovement->GetMaxSpeed(); + + UGameplayStatics::GetPlayerController(this, 0)->Possess(this); +} + +void ABugPlacerPawn::Deactivate() +{ + UGameplayStatics::GetPlayerController(this, 0)->Possess(this->OriginalPlayer); + + this->Destroy(); +} diff --git a/Source/Unrealzilla/Public/BugPlacerPawn.h b/Source/Unrealzilla/Public/BugPlacerPawn.h index 4396baa..4223ed8 100644 --- a/Source/Unrealzilla/Public/BugPlacerPawn.h +++ b/Source/Unrealzilla/Public/BugPlacerPawn.h @@ -19,10 +19,22 @@ public: virtual void BeginPlay() override; virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; + UFUNCTION(BlueprintCallable) + void Activate(); + + UFUNCTION(BlueprintCallable) + void Deactivate(); + +protected: + UPROPERTY(BlueprintReadWrite) + float SavedMaxSpeed = 0.0f; + private: UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true")) TObjectPtr SphereComponent; UPROPERTY(BlueprintReadOnly, VisibleAnywhere, meta=(AllowPrivateAccess="true")) TObjectPtr PawnMovement; + + TObjectPtr OriginalPlayer; };