7#include "GameFramework/FloatingPawnMovement.h"
8#include "GameFramework/PlayerController.h"
9#include "Components/SceneComponent.h"
10#include "NiagaraFunctionLibrary.h"
11#include "NiagaraSystem.h"
20 UNiagaraSystem* NiagaraSystem = LoadObject<UNiagaraSystem>(
nullptr, TEXT(
"/Game/Agrarsense/Particles/WaterAndSnow/NS_Particles.NS_Particles"));
23 NiagaraComponent = UNiagaraFunctionLibrary::SpawnSystemAttached(NiagaraSystem, this->GetRootComponent(),
24 FName(
"NiagaraEmitterSocketName"),
25 FVector(0.0, 0.0, 150.0f), FRotator::ZeroRotator, EAttachLocation::KeepRelativeOffset,
true);
36 Super::EndPlay(EndPlayReason);
50 if (!IsPlayerControlled())
58 FVector TargetLocation =
Transform.GetLocation();
59 FVector Direction = GetActorLocation() - TargetLocation;
60 Direction.Normalize();
63 FVector NewLocation = TargetLocation + Direction * 20.0f;
65 FRotator NewRotation = (TargetLocation - NewLocation).ToOrientationRotator();
67 SetActorLocationAndRotation(NewLocation, NewRotation);
71 APlayerController* PlayerController = Cast<APlayerController>(GetController());
74 PlayerController->SetControlRotation(
Transform.Rotator());
82 FTransform
Transform = Actor->GetActorTransform();
97 DetachFromActor(FDetachmentTransformRules::KeepRelativeTransform);
100 FVector Offset = FVector(0.0f, 0.0f, HeightOffset);
102 FVector TargetActorLocation = Actor->GetActorLocation();
104 FVector DirectionToActor = TargetActorLocation - GetActorLocation();
105 DirectionToActor.Normalize();
108 APlayerController* PlayerController = Cast<APlayerController>(GetController());
109 if (PlayerController)
113 DisableInput(PlayerController);
115 FRotator NewRotation = DirectionToActor.ToOrientationRotator();
116 PlayerController->SetControlRotation(NewRotation);
120 FVector NewLocation = TargetActorLocation + DirectionToActor * -DistanceToActor + Offset;
123 USceneComponent* Root = Actor->GetRootComponent();
126 AttachToComponent(Root, FAttachmentTransformRules::KeepRelativeTransform);
127 SetActorLocation(NewLocation);
141 FVector Offset = FVector(0.0f, 0.0f, HeightOffset);
143 FVector TargetActorLocation = Actor->GetActorLocation();
145 FVector DirectionToActor = TargetActorLocation - GetActorLocation();
146 DirectionToActor.Normalize();
149 APlayerController* PlayerController = Cast<APlayerController>(GetController());
150 if (PlayerController)
152 FRotator NewRotation = DirectionToActor.ToOrientationRotator();
153 PlayerController->SetControlRotation(NewRotation);
157 FVector NewLocation = TargetActorLocation + DirectionToActor * -DistanceToActor + Offset;
159 SetActorLocation(NewLocation);
166 DetachFromActor(FDetachmentTransformRules::KeepRelativeTransform);
172 APlayerController* PlayerController = Cast<APlayerController>(GetController());
174 if (PlayerController)
176 EnableInput(PlayerController);
194 if (FloatingMovement)
196 FloatingMovement->MaxSpeed = MaxSpeed;
203 if (FloatingMovement)
205 return FloatingMovement->MaxSpeed;
214 return Cast<UFloatingPawnMovement>(GetMovementComponent());
221 if (!IsPlayerControlled())
231 SetActorLocationAndRotation(
Transform.GetLocation(),
Transform.GetRotation().Rotator());
235 APlayerController* PlayerController = Cast<APlayerController>(GetController());
236 if (PlayerController)
238 PlayerController->SetControlRotation(
Transform.Rotator());
static void HideComponentForAllCameras(UPrimitiveComponent *PrimitiveComponent)
void SetMaxSpeed(float MaxSpeed=1500.0f)
void TeleportToActorFollowLocation(AActor *Actor, const float DistanceToActor=1500.0f, const float HeightOffset=500.0f)
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
void StopFollowingAnyActor(bool EnableInputs=true)
FFollowTargetChanged OnFollowTargetChanged
void FollowActor(AActor *Actor, bool DisableInputs=true, const float DistanceToActor=150.0f, const float HeightOffset=10.0f)
void TeleportToActorLocation(const AActor *Actor)
TWeakObjectPtr< AActor > Target
UNiagaraComponent * NiagaraComponent
UFloatingPawnMovement * GetFloatingPawnMovement()
void SetNiagaraComponentVisibility(bool Visible)
virtual void BeginPlay() override
void TeleportSpectator(const FTransform &Transform)
void TeleportToLevelTeleportLocation(FLevelTeleportLocation TeleportLocation)
FTransform TeleportLocationTransform