This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public GameObject target; | |
void OnTriggerEnter() | |
{ | |
CharacterController controller = target.GetComponent<CharacterController>(); | |
if (controller != null) | |
{ | |
controller.enabled = false; | |
target.transform.position = new Vector3(target.transform.position.x, target.transform.position.y, target.transform.position.z + 2500); | |
controller.enabled = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#include "Tracker.h" | |
// Sets default values | |
ATracker::ATracker() | |
{ | |
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ATracker::Tick(float DeltaTime) | |
{ | |
Super::Tick(DeltaTime); | |
// Find Tracker if trackerID is -1 else update tracker | |
if (trackerID == -1) | |
{ | |
// Loop through tracker ids skipping the first one because that is our null HMD. | |
for (uint32_t i = 1; i <= 8; i++) { | |
vr::HmdMatrix34_t posMat = UpdateTracker(i); | |
// Verify the postion of the tracker isn't vector zero. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vr::HmdMatrix34_t ATracker::UpdateTracker(int id) | |
{ | |
//Get Tracker Pose | |
vr::VRControllerState_t *state = new vr::VRControllerState_t(); | |
vr::TrackedDevicePose_t *pose = new vr::TrackedDevicePose_t(); | |
vrSystem->GetControllerStateWithPose(vr::ETrackingUniverseOrigin::TrackingUniverseStanding, id, state, sizeof(vr::VRControllerState_t), pose); | |
//Get Pose Position | |
vr::HmdMatrix34_t posMat = pose->mDeviceToAbsoluteTracking; | |
// Update tracker only if we have decided which tracker to use | |
if (trackerID != -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ATracker::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
// Grab player controller so we can setup the camera and enable input | |
APlayerController* playerController = UGameplayStatics::GetPlayerController(this, 0); | |
EnableInput(playerController); // This is probably not needed unless you need to receive input like keyboard events. | |
playerController->SetViewTargetWithBlend(this, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ATracker::ATracker() | |
{ | |
// 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; | |
// Initialize VR | |
vr::EVRInitError peError; | |
vrSystem = vr::VR_Init(&peError, vr::EVRApplicationType::VRApplication_Other); | |
// Setup trackerID to -1 so we can test when it is set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected: | |
// Called when the game starts or when spawned | |
virtual void BeginPlay() override; | |
// Our connnection to the VR System | |
vr::IVRSystem* vrSystem; | |
// ID for which tracker to utilize | |
uint32_t trackerID; | |
// I always add a scene component as my root object as default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* insert after Actor.h */ | |
#include "openvr.h" | |
#include "Runtime/Engine/Classes/Camera/CameraComponent.h" | |
#include "Runtime/Core/Public/GenericPlatform/GenericPlatformMath.h" | |
#include "Kismet/GameplayStatics.h" | |
/* leave Tracker.generate.h at the end */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "OpenVR", "SteamVR", "SteamVRController", "HeadMountedDisplay" }); |
NewerOlder