ValveSoftware / steamvr_unreal_plugin

SteamVR Input Unreal Plugin - Documentation at: https://github.com/ValveSoftware/steamvr_unreal_plugin/wiki Sample project (UE4.15-4.23): https://github.com/ValveSoftware/steamvr_unreal_plugin/wiki/sample/SteamVRInputPlugin.zip Sample Project (UE.424+): https://github.com/ValveSoftware/steamvr_unreal_plugin/wiki/sample/SteamVRInputPlugin_UEIntegrated.7z
Other
166 stars 29 forks source link

Why is there no analog value from thumbstick on the index? #176

Closed RepublicofNumbers closed 3 years ago

RepublicofNumbers commented 3 years ago

I am trying to get the value of the thumbstick but it does output any value. The gamepad does return a value.

Here is my code:

``` // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "MotionControllerComponent.h" #include "HandController.generated.h" UCLASS() class TEST1_API AHandController : public AActor { GENERATED_BODY() public: // Sets default values for this actor's properties AHandController(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; private: UPROPERTY(VisibleAnywhere) UMotionControllerComponent* MotionController; }; ``` ``` // Fill out your copyright notice in the Description page of Project Settings. #include "HandController.h" // Sets default values AHandController::AHandController() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; MotionController = CreateDefaultSubobject(TEXT("MotionController")); SetRootComponent(MotionController); MotionController->SetTrackingSource(EControllerHand::Right); MotionController->SetShowDeviceModel(true) ; } // Called when the game starts or when spawned void AHandController::BeginPlay() { Super::BeginPlay(); } // Called every frame void AHandController::Tick(float DeltaTime) { Super::Tick(DeltaTime); } ``` ``` // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GameFramework/Pawn.h" #include "Camera/CameraComponent.h" #include "VRPawn.generated.h" UCLASS() class TEST1_API AVRPawn : public APawn { GENERATED_BODY() public: // Sets default values for this pawn's properties AVRPawn(); protected: // Called when the game starts or when spawned virtual void BeginPlay() override; public: // Called every frame virtual void Tick(float DeltaTime) override; // Called to bind functionality to input virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; private: // Config UPROPERTY(EditDefaultsOnly) TSubclassOf HandControllerClass; //Components UPROPERTY(VisibleAnywhere) USceneComponent* VRRoot; UPROPERTY(VisibleAnywhere) UCameraComponent* Camera; UPROPERTY() AHandController* RightHandController; void MoveRight(float Power); }; ``` ``` // Fill out your copyright notice in the Description page of Project Settings. #include "VRPawn.h" #include "Engine/World.h" #include "HandController.h" // Sets default values AVRPawn::AVRPawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; VRRoot = CreateDefaultSubobject(TEXT("VRRoot")); SetRootComponent(VRRoot); Camera = CreateDefaultSubobject(TEXT("Camera")); Camera->SetupAttachment(VRRoot); } // Called when the game starts or when spawned void AVRPawn::BeginPlay() { Super::BeginPlay(); RightHandController = GetWorld()->SpawnActor(HandControllerClass); RightHandController->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetIncludingScale); RightHandController->SetOwner(this); } // Called every frame void AVRPawn::Tick(float DeltaTime) { Super::Tick(DeltaTime); } // Called to bind functionality to input void AVRPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAxis(TEXT("MoveLeft_X"), this, &AVRPawn::MoveRight); } void AVRPawn::MoveRight(float Power) { UE_LOG(LogTemp, Warning, TEXT("Power: %f"), Power); } ```

bind_Index

Thanks!

1runeberg commented 3 years ago

Hi @RepublicofNumbers - As the engine doesn't support Vector2 input in the Input UI, the plugin needs two axis mappings mapped to the X and Y axis of the individual controller's thumbstick.

Here's our instructions from the Quickstart in this repo's wiki:

Vector2 Actions - As Unreal doesn't have a concept of a Vector2 action we auto group two vector1 actions with names that end with _X and _Y. For example, to create a mapping for MoveLeft you will need a MoveLeft_X and a MoveLeft_Y that you bind to their corresponding controller axis. See the sample inputs for an example. (SteamVR Input Menu - Add Sample Inputs)

You can also have a look at the following closed issues for more info:

https://github.com/ValveSoftware/steamvr_unreal_plugin/issues/107#issuecomment-570951816 https://github.com/ValveSoftware/steamvr_unreal_plugin/issues/142

RepublicofNumbers commented 3 years ago

I had looked at the closed issue #142 but I did not realize it needed both Axis mapped, thank you so much Rune!

I'm eagerly looking forward to the next chapter in you Unreal Education VR Series !! it's pure gold.

Thanks again !