7#include "GameFramework/FloatingPawnMovement.h"
8#include "GameFramework/PlayerController.h"
9#include "Components/SceneComponent.h"
10#include "NiagaraFunctionLibrary.h"
11#include "NiagaraSystem.h"
22 UNiagaraSystem* NiagaraSystem = LoadObject<UNiagaraSystem>(
nullptr, TEXT(
"/Game/Agrarsense/Particles/WaterAndSnow/NS_Particles.NS_Particles"));
25 NiagaraComponent = UNiagaraFunctionLibrary::SpawnSystemAttached(NiagaraSystem, this->GetRootComponent(),
26 FName(
"NiagaraEmitterSocketName"),
27 FVector(0.0, 0.0, 150.0f), FRotator::ZeroRotator, EAttachLocation::KeepRelativeOffset,
true);
35 FVector RelativePosition = FVector(0.0f, 0.0f, 0.0f);
36 float OverlapBoundsSize = 15.0f;
41 Params.
Size = FVector(OverlapBoundsSize, OverlapBoundsSize, OverlapBoundsSize);
44 FString OverlapSensorID =
"spectator/overlap";
50 Super::EndPlay(EndPlayReason);
70 if (!IsPlayerControlled())
78 FVector TargetLocation =
Transform.GetLocation();
79 FVector Direction = GetActorLocation() - TargetLocation;
80 Direction.Normalize();
83 FVector NewLocation = TargetLocation + Direction * 20.0f;
85 FRotator NewRotation = (TargetLocation - NewLocation).ToOrientationRotator();
87 SetActorLocationAndRotation(NewLocation, NewRotation);
91 APlayerController* PlayerController = Cast<APlayerController>(GetController());
94 PlayerController->SetControlRotation(
Transform.Rotator());
102 FTransform
Transform = Actor->GetActorTransform();
117 DetachFromActor(FDetachmentTransformRules::KeepRelativeTransform);
120 FVector Offset = FVector(0.0f, 0.0f, HeightOffset);
122 FVector TargetActorLocation = Actor->GetActorLocation();
124 FVector DirectionToActor = TargetActorLocation - GetActorLocation();
125 DirectionToActor.Normalize();
128 APlayerController* PlayerController = Cast<APlayerController>(GetController());
129 if (PlayerController)
133 DisableInput(PlayerController);
135 FRotator NewRotation = DirectionToActor.ToOrientationRotator();
136 PlayerController->SetControlRotation(NewRotation);
140 FVector NewLocation = TargetActorLocation + DirectionToActor * -DistanceToActor + Offset;
143 USceneComponent* Root = Actor->GetRootComponent();
146 AttachToComponent(Root, FAttachmentTransformRules::KeepRelativeTransform);
147 SetActorLocation(NewLocation);
156 FVector Offset = FVector(0.0f, 0.0f, HeightOffset);
158 FVector DirectionToActor = TargetLocation - GetActorLocation();
159 DirectionToActor.Normalize();
162 APlayerController* PlayerController = Cast<APlayerController>(GetController());
163 if (PlayerController)
165 FRotator NewRotation = DirectionToActor.ToOrientationRotator();
166 PlayerController->SetControlRotation(NewRotation);
170 FVector NewLocation = TargetLocation + DirectionToActor * -DistanceToLocation + Offset;
172 SetActorLocation(NewLocation);
182 FVector TargetLocation = Actor->GetActorLocation();
190 DetachFromActor(FDetachmentTransformRules::KeepRelativeTransform);
196 APlayerController* PlayerController = Cast<APlayerController>(GetController());
198 if (PlayerController)
200 EnableInput(PlayerController);
218 if (FloatingMovement)
220 FloatingMovement->MaxSpeed = MaxSpeed;
227 if (FloatingMovement)
229 return FloatingMovement->MaxSpeed;
238 return Cast<UFloatingPawnMovement>(GetMovementComponent());
245 if (!IsPlayerControlled())
255 SetActorLocationAndRotation(
Transform.GetLocation(),
Transform.GetRotation().Rotator());
259 APlayerController* PlayerController = Cast<APlayerController>(GetController());
260 if (PlayerController)
262 PlayerController->SetControlRotation(
Transform.Rotator());
static void HideComponentForAllCameras(UPrimitiveComponent *PrimitiveComponent)
void SetMaxSpeed(float MaxSpeed=1500.0f)
AOverlapSensor * OverlapSensor
void TeleportToActorFollowLocation(AActor *Actor, const float DistanceToActor=1500.0f, const float HeightOffset=500.0f)
void TeleportToFollowLocation(FVector TargetLocation, const float DistanceToLocation, const float HeightOffset)
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)
static AOverlapSensor * SpawnOverlapSensor(const FTransform &transform, FOverlapSensorParameters Parameters, const FString sensorIdentifier, const FString sensorName, AActor *Parent=nullptr)
FTransform TeleportLocationTransform