8#include "Kismet/GameplayStatics.h"
9#include "Kismet/KismetMathLibrary.h"
13 static ConstructorHelpers::FObjectFinder<UStaticMesh> CylinderMeshFinder(TEXT(
"StaticMesh'/PixoCore/Meshes/BasicShapes/Cylinder.Cylinder'"));
14 UStaticMesh* CylinderMesh = CylinderMeshFinder.Object;
16 static ConstructorHelpers::FObjectFinder<UStaticMesh> CylinderRingMeshFinder(TEXT(
"StaticMesh'/PixoCore/Meshes/Controller/SM_FatCylinder.SM_FatCylinder'"));
17 UStaticMesh* CylinderRingMesh = CylinderRingMeshFinder.Object;
19 static ConstructorHelpers::FObjectFinder<UMaterial> TeleportCylinderMaterialFinder(TEXT(
"Material'/PixoCore/Materials/Controller/TeleportSpot/M_TeleportSpotPreviews.M_TeleportSpotPreviews'"));
20 UMaterial* CylinderMaterial = TeleportCylinderMaterialFinder.Object;
22 static ConstructorHelpers::FObjectFinder<UMaterial> ArcEndPointMaterialFinder(TEXT(
"Material'/PixoCore/Materials/Controller/TeleportSpot/M_TeleporterSpotMaterial.M_TeleporterSpotMaterial'"));
23 UMaterial* ArcEndPointMaterial = ArcEndPointMaterialFinder.Object;
35 TeleportersSpotRing = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(
"TeleportersSpotRing"));
95 TArray<AActor*> FoundActors;
96 UGameplayStatics::GetAllActorsOfClass(GetWorld(), ATeleportersSpot::StaticClass(), FoundActors);
98 for (
auto FoundActor : FoundActors)
105 const FTransform& ActorTransform,
const FVector& VRLocation,
const FRotator& ActorRotation)
124 const FVector PivotPoint = VRLocation;
125 const FVector InvPivotPoint = UKismetMathLibrary::InverseTransformLocation(ActorTransform, PivotPoint);
128 FVector LastValidTeleportLocation;
131 if (TeleportersSpot->IsActive())
133 LastValidTeleportLocation = TeleportersSpot->TeleportersSpotCylinder->GetComponentLocation();
134 LastValidTeleportersSpot = TeleportersSpot;
141 UVRExpansionFunctionLibrary::RotateAroundPivot(FRotator::ZeroRotator, TeleportToLocation, ActorRotation, InvPivotPoint,
TimedLocation,
TimedRotation,
true);
143 auto FadeInFinishedEvent = [
this, LastValidTeleportersSpot, PixoVRCharacter]()
161 Super::ActivateTeleporter(InActivate);
165 TeleportersSpot->TeleportersSpotCylinder->SetVisibility(InActivate);
166 TeleportersSpot->TeleportersSpotRing->SetVisibility(InActivate);
172 TArray<FVector> TracePoints;
175 FVector TraceLocation;
189 FVector StartPos(FVector::ZeroVector);
190 FVector LaunchVelocity (FVector::ZeroVector);
195 TArray<TEnumAsByte<EObjectTypeQuery>> ObjectTypes;
196 ObjectTypes.Add(UEngineTypes::ConvertToObjectType(ECC_WorldStatic));
198 FPredictProjectilePathParams Params;
199 Params.bTraceWithCollision =
true;
200 Params.bTraceComplex =
false;
201 Params.DrawDebugType = EDrawDebugTrace::None;
202 Params.DrawDebugTime = 0.0f;
203 Params.SimFrequency = 30.0f;
204 Params.OverrideGravityZ = 0.0f;
205 Params.ObjectTypes = ObjectTypes;
206 Params.bTraceWithChannel =
false;
207 Params.ProjectileRadius = 0.0f;
208 Params.StartLocation = StartPos;
209 Params.MaxSimTime = 2.0f;
210 Params.LaunchVelocity = LaunchVelocity;
212 FPredictProjectilePathResult PredictResult;
213 bool bHit = UGameplayStatics::PredictProjectilePath(
this, Params, PredictResult);
220 FHitResult HitResult;
221 HitResult = PredictResult.HitResult;
222 TracePoints.Empty(PredictResult.PathData.Num());
224 for (
const FPredictProjectilePathPointData& PathPoint : PredictResult.PathData)
226 TracePoints.Add(PathPoint.Location);
229 TraceLocation = HitResult.Location;
233 FTransform CylinderTransform = TeleportersSpot->TeleportersSpotCylinder->GetComponentTransform();
234 FVector CylinderScale = CylinderTransform.GetScale3D();
235 FVector RingScale = TeleportersSpot->TeleportersSpotRing->GetComponentTransform().GetScale3D();
237 float CylinderRadius = TeleportersSpot->TeleportersSpotCylinder->Bounds.SphereRadius * CylinderScale.GetMax() + TeleportersSpot->BufferBoundsRadiusDetection;
238 float CylinderHalfHeight = TeleportersSpot->TeleportersSpotRing->Bounds.BoxExtent.Z * RingScale.Z + TeleportersSpot->BufferBoundsHeightDetection;
240 FVector LocationRelativeToComponent = CylinderTransform.InverseTransformPosition(TraceLocation);
241 if (TeleportersSpot->IsSpotHaveCubeShape)
245 FMath::Abs(LocationRelativeToComponent.Z) <= CylinderHalfHeight)
248 TeleportersSpot->ActivateSpot(
true);
254 float DistanceToCenterXY = LocationRelativeToComponent.Size2D();
256 if (DistanceToCenterXY <= CylinderRadius && FMath::Abs(LocationRelativeToComponent.Z) <= CylinderHalfHeight)
259 TeleportersSpot->ActivateSpot(
true);
274 TeleportersSpot->ActivateSpot(
false);
280 APixoVRCharacter* PixoVRCharacter = Cast<APixoVRCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
bool AtListOneTeleportersActive()
float SpotTeleporterExtendCoeficient
virtual void ExecuteTeleportation(UVRBaseCharacterMovementComponent *InMovementComponent, const FTransform &ActorTransform, const FVector &VRLocation, const FRotator &ActorRotation) override
Execute the teleportation. It checks if there is a valid teleport destination before executing the te...
bool TraceTeleportDestination(TArray< FVector > &TracePoints, FVector &TraceLocation)
virtual void BeginPlay() override
virtual void TickTeleporter(float DeltaTime) override
Tick the Teleporter.
UVRBaseCharacterMovementComponent * MovementComponent
virtual void ActivateTeleporter(bool InActivate) override
Activate or deactivate the Teleporter.
void DeactivateAllSpots()
TArray< ATeleportersSpot * > TeleportersSpots
UPROPERTY()
Pixo VR Character This class represents the main character in the Pixo VR game. It extends the AVRCha...
USoundCue * TeleportSoundCue
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "PixoVR", meta = (EditCondition = "bTeleportSo...
bool bTeleportSoundsEnabled
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "PixoVR")
ATeleporterBase * TeleportControllerRight
UPROPERTY(BlueprintReadOnly, Replicated, Category = "PixoVR")
ATeleporterBase * TeleportControllerLeft
UPROPERTY(BlueprintReadOnly, Replicated, Category = "PixoVR")
float TeleportLaunchVelocity
UPROPERTY(EditAnywhere, Category = "PixoVR | Teleporter")
bool bIsValidTeleportDestination
UPROPERTY(BlueprintReadOnly, Category = "PixoVR | Teleporter")
virtual bool IsActivated()
Check if the teleporter is activated.
float FadeInDuration
UPROPERTY(EditAnywhere, Category = "PiUpdateMotionControllerRotationxoVR | Teleporter")
float FadeOutDuration
UPROPERTY(EditAnywhere, Category = "PixoVR | Teleporter")
virtual void FVector GetTeleportDestination(const FVector &OriginalLocation)
Get the teleport destination.
void GetTeleportationTransform(FVector &Location, FVector &ForwardVector)
Get the teleportation transform which includes location and orientation.
virtual void UpdateArcEndpoint(const FVector &NewLocation, bool ValidLocationFound)
Update the endpoint of the arc spline.
virtual void UpdateArcSpline(TArray< FVector > &SplinePoints, bool ValidLocationFound)
Update the arc spline.
bool bDrawArcSpline
UPROPERTY(EditAnywhere, Category = "PixoVR | Teleporter")
UMaterialInstanceDynamic * RingMaterialInstanceDynamic
UPROPERTY()
FColor ActiveColorOfSpot
UPROPERTY(EditAnywhere, Category = "Spot | Color")
FColor NotActiveColorOfSpot
UPROPERTY(EditAnywhere, Category = "Spot | Color")
UMaterialInstanceDynamic * CylinderMaterialInstanceDynamic
UPROPERTY()
void ActivateSpot(bool InActivate)
Activate or deactivate the Teleporter.
virtual void BeginPlay() override
UStaticMeshComponent * TeleportersSpotRing
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category = "Spot")
FOnCharacterTeleportedOnSpot OnCharacterTeleportedOnSpot
UPROPERTY(BlueprintAssignable, Category = "Spot | Delegates")
UStaticMeshComponent * TeleportersSpotCylinder
UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category = "Spot")
static FUNCTION_NON_NULL_RETURN_START TEventType * NewEvent(APlayerController *Executor=nullptr) FUNCTION_NON_NULL_RETURN_END
Creates a new event of the specified type.