diff --git a/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp b/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp index 1ab4410875ce73d3fff4caec2755d16b4bc6cdc6..6fa1b15809498c6f4a2b0fc7eaa21376037a38ee 100644 --- a/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp +++ b/Source/RWTHVRToolkit/Private/Pawn/BasicVRInteractionComponent.cpp @@ -43,6 +43,7 @@ void UBasicVRInteractionComponent::BeginPlay() //WidgetInteractionComponent InteractionDistance = MaxClickDistance; + InteractionRay->SetRelativeScale3D(FVector(MaxClickDistance / 100.0f, 0.5f, 0.5f)); //the ray model has a length of 100cm (and is a bit too big in Y/Z dir) SetInteractionRayVisibility(InteractionRayVisibility); } @@ -196,16 +197,13 @@ void UBasicVRInteractionComponent::TickComponent(float DeltaTime, ELevelTick Tic LastActorHit = HitActor; // Store the actor that was hit to have access to it in the next frame as well } -void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance, float InMaxClickDistance) +void UBasicVRInteractionComponent::Initialize(USceneComponent* RayEmitter) { if(InteractionRayEmitter) return; /* Return if already initialized */ InteractionRayEmitter = RayEmitter; - MaxGrabDistance = InMaxGrabDistance; - MaxClickDistance = InMaxClickDistance; InteractionRay->AttachToComponent(RayEmitter, FAttachmentTransformRules::KeepRelativeTransform); - InteractionRay->SetRelativeScale3D(FVector(MaxClickDistance/100.0f, 1.0f, 1.0f)); //the ray model has a length of 100cm this->AttachToComponent(RayEmitter, FAttachmentTransformRules::KeepRelativeTransform); } diff --git a/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h b/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h index 9b100179267c2bbb0a1f48571e42a75eb7811443..e62fbf21485da813efa4317cd553169af4beb7a0 100644 --- a/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h +++ b/Source/RWTHVRToolkit/Public/Pawn/BasicVRInteractionComponent.h @@ -36,13 +36,13 @@ public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - UPROPERTY(BlueprintReadWrite) float MaxGrabDistance = 50; - UPROPERTY(BlueprintReadWrite) float MaxClickDistance = 500; + UPROPERTY(EditAnywhere,BlueprintReadWrite) float MaxGrabDistance = 50; + UPROPERTY(EditAnywhere,BlueprintReadWrite) float MaxClickDistance = 500; // Enable this if you want to interact with Targetable classes or use EInteractionRayVisibility::VisibleOnHoverOnly UPROPERTY(EditAnywhere) bool bCanRaytraceEveryTick = false; UPROPERTY(EditAnywhere) TEnumAsByte<EInteractionRayVisibility> InteractionRayVisibility = EInteractionRayVisibility::Invisible; - UFUNCTION(BlueprintCallable) void Initialize(USceneComponent* RayEmitter, float InMaxGrabDistance = 50, float InMaxClickDistance = 500); + UFUNCTION(BlueprintCallable) void Initialize(USceneComponent* RayEmitter); UFUNCTION(BlueprintCallable, BlueprintPure) AActor* GetGrabbedActor() const { return GrabbedActor;} UFUNCTION(BlueprintCallable, BlueprintPure) USceneComponent* GetInteractionRayEmitter() const { return InteractionRayEmitter; }