Download

Using C++ For Bow and Arrow Game HTC Vive

Hi I am wondering if I am able to use c++ for programming the player controller or should I just stick to using the blueprints for the motion controllers? I cant seem to find much tutorials on using c++ when making a vive game in ue4 so if anyone has links please post them. Thanks.

Don’t know about tutorials, but I used C++. It works absolutely the same way.
[yourproject.Build.cs]


PublicDependencyModuleNames.AddRange(new string] { "HeadMountedDisplay", "SteamVR", "SteamVRController" });

[yourpawn.h]



UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class USteamVRChaperoneComponent* SteamVRChaperone;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UMotionControllerComponent* MControllerLeft;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
class UMotionControllerComponent* MControllerRight;

[yourpawn.cpp constructor]



MControllerLeft = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("MControllerLeft"));
MControllerLeft->SetupAttachment(ControllersRoot);
MControllerLeft->Hand = EControllerHand::Left;

MControllerRight = CreateDefaultSubobject<UMotionControllerComponent>(TEXT("MControllerRight"));
MControllerRight->SetupAttachment(ControllersRoot);
MControllerRight->Hand = EControllerHand::Right;

SteamVRChaperone = CreateDefaultSubobject<USteamVRChaperoneComponent>(TEXT("SteamVRChaperone"));

We use C++ exclusively for player control. Unlike the description above where Yuri added Motioncontroller components to the Pawn, we treat the two hands as individual actors. We derive a new custom actor and then just update the position of the actor using the Steam VR calls.

You can see if the hand is active and get the position and rotation like this:
Code:

Either method would work fine. If you are trying to do advanced stuff with the controls like gesture recognition, I would not use Blueprint for the controls. C++ will be much easier to debug and do complex stuff.

Thank you both for the tips. As I get more into it I will surely ask some more specific questions.

I tried to avoid additional tick() calls. I use separate actors for player’s hands too, but i just attach them to motion controller components of the pawn at game start.

I don’t think you’re benefiting from the late update of the motioncontroller transform this way? I could be wrong.

We haven’t seen any problem with latency on the controls. But we don’t rely on the update of the controller actors to position the controls. The Player Character coordinates the hands which are both registered with the player at start.

UPDATE: Solved. I just included “SteamVRChaperoneComponent.h” in VR_PlayerChaperone.h. I assumed step 2 below meant I didnt have to include that file.

Any idea on why I am getting these errors:
82b6c9730200a0c9e61204bc42ad9474ebb68b2a.jpeg
My steps to making this is as follows:

  1. Create C++ Class of type ACharacter called VR_PlayerChaperone
  2. in project.Build.cs added the following line of code:
    PublicDependencyModuleNames.AddRange(new string] { “HeadMountedDisplay”, “SteamVR”, “SteamVRController” });
  3. in .h added the following lines of code:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
    class USteamVRChaperoneComponent* SteamVRChaperone;
  4. in .cpp constructor added the following line of code:
    SteamVRChaperone = CreateDefaultSubobject<USteamVRChaperoneComponent>(TEXT(“SteamVRChaperone”));

oops, i missed it

#include “MotionControllerComponent.h”
#include “SteamVRChaperoneComponent.h”

I cannot get the USteamVRFunctionLibrary to work, it all works via blueprints but not in c++ for some reason.

Did you include “SteamVRFunctionLibrary.h” ?

Yes, as well as in *.build.cs: PublicDependencyModuleNames.AddRange(new string] { “HeadMountedDisplay”, “SteamVR”, “SteamVRController” });

can you show me the line of code you used to call the function ? Also is it an error on compile or does it say something is wrong when you type the line of code? In VS it always highlights the USteamVRFunctionLibrary:: as red and tells me to include the header file. If this is the problem you are having don’t worry about it because it will still compile successfully.

It seems so that it the steamVRlib isn’t found in build system paths. I’ll look further into it.

When I try this:

I can’t compile anymore, in the pawn .cpp file it underlines MControllerLeft saying that pointer to incomplete class type is not allowed and identifier “ControllersRoot” is undefined, what can i give as input there?

I got the steamvrlib to work, thanks for the help on that one. Next step is getting it to work in multiplayer.