Skip to content
Snippets Groups Projects
Select Git revision
  • dev/5.5
  • 5.5
  • dev/5.4
  • dev/5.3_downgrade
  • feature/experimenttime_hack
  • 5.4 default protected
  • 5.3 protected
  • _IntenSelect5.3
  • IntenSelect5.3
  • 4.27 protected
  • 4.26 protected
  • 5.0 protected
  • 4.22 protected
  • 4.21 protected
  • UE5.4-2024.1-rc1
  • UE5.3-2023.1-rc3
  • UE5.3-2023.1-rc2
  • UE5.3-2023.1-rc
18 results

TurnComponent.h

Blame
  • TurnComponent.h 2.54 KiB
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "MovementComponentBase.h"
    #include "TurnComponent.generated.h"
    
    class UMotionControllerComponent;
    
    UCLASS(Blueprintable)
    class RWTHVRTOOLKIT_API UTurnComponent : public UMovementComponentBase
    {
    	GENERATED_BODY()
    
    public:
    	virtual void SetupPlayerInput(UInputComponent* PlayerInputComponent) override;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement")
    	bool bTurnWithLeftHand = true;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement")
    	bool bAllowTurning = true;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning",
    			  meta = (EditCondition = "bAllowTurning"))
    	bool bSnapTurn = false;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning",
    			  meta = (EditCondition = "!bSnapTurn && bAllowTurning"))
    	float TurnRateFactor = 1.0f;
    
    	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VR Movement|Turning",
    			  meta = (EditCondition = "bSnapTurn && bAllowTurning", ClampMin = 0, ClampMax = 360))
    	float SnapTurnAngle = 22.5;
    
    	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions")
    	class UInputAction* Turn;
    
    	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions")
    	class UInputAction* DesktopTurn;
    
    	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "VR Movement|Input|Actions")
    	class UInputAction* DesktopTurnCondition;
    
    	/**
    	 * Called every tick as long as stick input is received to allow for continuous turning
    	 * @param Value Stick input value determines turn direction and turn speed
    	 */
    	UFUNCTION(BlueprintCallable)
    	void OnBeginTurn(const FInputActionValue& Value);
    
    	/**
    	 * Called once if stick input is received to rotate player at constant value
    	 * @param Value Stick input value determines turn direction
    	 */
    	UFUNCTION(BlueprintCallable)
    	void OnBeginSnapTurn(const FInputActionValue& Value);
    
    
    	// A separate button has to be pressed, for when mouse movement should contribute to turning
    	UFUNCTION()
    	void StartDesktopRotation();
    
    	UFUNCTION()
    	void EndDesktopRotation();
    
    private:
    	UPROPERTY()
    	UMotionControllerComponent* RotationHand;
    
    	/**
    	 * If we just use VRPawn->AddControllerYawInput(Yaw), rotation is around tracking origin instead of the actual
    	 * player position This function updates the pawns rotation and location to result in a rotation around the users
    	 * tracked position.
    	 */
    	void RotateCameraAndPawn(float Yaw) const;
    	bool bApplyDesktopRotation;
    };