Skip to content
Snippets Groups Projects
Select Git revision
  • 6d4fb12dea39d34957ea9a3717fb710b2731e739
  • dev/5.3 default
  • feature/scaleTeleport
  • feature/scaleAndHeightTeleport
  • 5.3
  • 5.0
  • TempNav
  • fix/DisplayClusterTemplateCode
  • fix_5.3/DisplayClusterTemplateFix
  • ReworkedToolkit
  • dev/5.2
  • feature/make_interaction_ray_accesible
  • dev/5.1
  • 4.27
  • 4.26 protected
  • 4.22
  • 4.21
17 results

TeleportationComponent.h

Blame
  • Forked from LuFG VR VIS / VR-Group / Unreal-Development / Plugins / RWTH VR Toolkit
    Source project has a limited visibility.
    TeleportationComponent.h 4.31 KiB
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "Components/ActorComponent.h"
    #include "Pawn/RWTHVRPawn.h"
    #include "NiagaraComponent.h"
    #include "Kismet/GameplayStaticsTypes.h"
    #include "Pawn/Navigation/MovementComponentBase.h"
    #include "UI/TeleportVisualizer.h"
    
    #include "TeleportationComponent.generated.h"
    
    
    UENUM(BlueprintType)
    enum class ETeleportState : uint8
    {
    	BaseState UMETA(DisplayName = "Base/Idle State"),
    	HorizontalSelection UMETA(DisplayName = "Horizontal Location Selection"),
    	VerticalSelection UMETA(DisplayName = "Vertical Location Selection ")
    };
    
    
    UCLASS(Blueprintable)
    class RWTHVRTOOLKIT_API UTeleportationComponent : public UMovementComponentBase
    {
    	GENERATED_BODY()
    
    public:
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement")
    	bool bMoveWithRightHand = true;
    
    	/**
    	 * Whether the hit location of the teleport trace should be projected onto the navigation mesh
    	 * TODO: does currently not work, so leave it at false
    	 */
    	UPROPERTY(VisibleAnywhere, Category = "VR Movement|Teleport")
    	bool bUseNavMesh = false;
    
    	/**
    	 * If true, target location will not get projected onto the geometry.
    	 * Height of target location is defined in a second step, by holding the teleportation button
    	 * and moving the controller up or down.
    	 */
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Teleport")
    	bool bHeighTeleport = false;
    
    	/**
    	 * Speed at which the projectile shoots out from the controller to get the teleport location
    	 * Higher values = larger teleportation range
    	 */
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Teleport")
    	float TeleportLaunchSpeed = 800;
    
    	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions")
    	UInputAction* Teleport;
    	
    	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions")
    	UInputAction* CancelTeleport;
    
    	// Trace Visualization
    	UPROPERTY(EditAnywhere)
    	TSubclassOf<AActor> BPTeleportVisualizer;
    
    	UPROPERTY(EditDefaultsOnly)
    	UNiagaraSystem* TeleportTraceSystem;
    
    	UPROPERTY()
    	UNiagaraComponent* TeleportTraceComponent;
    	
    	/*Movement Input*/
    	UFUNCTION(BlueprintCallable)
    	void OnStartTeleportTrace(const FInputActionValue& Value);
    
    	void SetPreTravelInformationVisibility(bool bVisibility);
    
    	void SelectHorizontalLocation();
    
    	void SelectVerticalLocation();
    	
    	float GetAngleBetweenVectors(FVector Vector1, FVector Vector2);
    
    	UFUNCTION(BlueprintCallable)
    	void UpdateTeleportTrace(const FInputActionValue& Value);
    
    	UFUNCTION(BlueprintCallable)
    	void OnEndTeleportTrace(const FInputActionValue& Value);
    
    	UFUNCTION(BlueprintCallable)
    	void OnCancelTeleport(const FInputActionValue& Value);
    
    	bool IsValidTeleportLocation(const FHitResult& Hit, FVector& ProjectedLocation) const;
    
    	
    	virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override;
    
    	UPROPERTY(BlueprintReadOnly)
    	ATeleportVisualizer* TeleportVisualizer;
    
    	void PlayHapticEffect(UHapticFeedbackEffect_Base* HapticEffect, float Intensity);
    	
    private:
    	UPROPERTY()
    	UMotionControllerComponent* TeleportationHand;
    
    	UPROPERTY()
    	UMotionControllerComponent* RotationHand;
    
    	bool bTeleportTraceActive;
    	float TeleportProjectileRadius = 3.6;
    	float RotationArrowRadius = 10.0;
    
    	UPROPERTY()
    	FPredictProjectilePathResult PredictResult;
    
    	bool bValidTeleportLocation = false;
    
    	UPROPERTY()
    	FVector FinalTeleportLocation;
    
    	UPROPERTY()
    	float TwoStepThreshold = 0.99f;
    	
    	void CleanupTeleportVisualization();
    	bool bTeleportCancelled = false;
    
    	void UpdateUserPreview();
    
    	UPROPERTY()
    	ETeleportState TeleportState = ETeleportState::BaseState;
    
    	UPROPERTY()
    	FVector ReferenceVector;
    
    	bool bHorizontalPhaseCompleted;
    	bool bHasVerticalPhaseStarted;
    
    	UPROPERTY()
    	float Deadzone = 10;
    
    	UPROPERTY()
    	float VelocityZone = 30;
    
    	UPROPERTY()
    	float ElevationSpeed = 6; // speed for height changes below the velocity zone
    
    	UPROPERTY()
    	float VelocitySpeed = 0.2; // speed for height changes in the velocity zone
    	 
    	UPROPERTY()
    	bool hasLeftDeadZone = false; // used to apply the deadzone limitation only when no height change has been made
    
    	UPROPERTY()
    	float HeightOffset = 0;
    
    	UPROPERTY()
    	float AngularOffset = 0;
    	
    	UPROPERTY()
    	FVector SelectedHorizontalPosition;
    	UPROPERTY()
    	FPlane AngleProjectionPlane;
    
    	UPROPERTY()
    	bool bIsFirstHorizontalCall = true;
    	
    };