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);
136 FVector Offset = FVector(0.0f, 0.0f, HeightOffset);
138 FVector DirectionToActor = TargetLocation - GetActorLocation();
139 DirectionToActor.Normalize();
142 APlayerController* PlayerController = Cast<APlayerController>(GetController());
143 if (PlayerController)
145 FRotator NewRotation = DirectionToActor.ToOrientationRotator();
146 PlayerController->SetControlRotation(NewRotation);
150 FVector NewLocation = TargetLocation + DirectionToActor * -DistanceToLocation + Offset;
152 SetActorLocation(NewLocation);
162 FVector TargetLocation = Actor->GetActorLocation();
170 DetachFromActor(FDetachmentTransformRules::KeepRelativeTransform);
176 APlayerController* PlayerController = Cast<APlayerController>(GetController());
178 if (PlayerController)
180 EnableInput(PlayerController);
198 if (FloatingMovement)
200 FloatingMovement->MaxSpeed = MaxSpeed;
207 if (FloatingMovement)
209 return FloatingMovement->MaxSpeed;
218 return Cast<UFloatingPawnMovement>(GetMovementComponent());
225 if (!IsPlayerControlled())
235 SetActorLocationAndRotation(
Transform.GetLocation(),
Transform.GetRotation().Rotator());
239 APlayerController* PlayerController = Cast<APlayerController>(GetController());
240 if (PlayerController)
242 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)
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)
FTransform TeleportLocationTransform