Transform shows in Scene View on Runtime, but not in Camera (also: Vive Trackers)
Hi there,
I am currently working with a Vive Tracker to bring a drawer into Virtual Reality. To adjust the position and rotation of the mounted tracker in relation to the drawer, I took an example script from the Vive Tracker Guidelines (Page 29) and adjusted it slightly so that it now looks like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
public class Accessory : MonoBehaviour {
// Define Offset and Rotation in Unity Editor
public float dX = 0.0f;
public float dY = 0.0f;
public float dZ = 0.0f;
public float roll = 0.0f;
public float yaw = 0.0f;
public float pitch = 0.0f;
/*
// Define Offset and Rotation in Unity Editor
const float dX = 0.0f;
const float dY = -0.61f;
const float dZ = 0.0f;
const float roll = 0.5f;
const float yaw = 90.0f;
const float pitch = 0.3f;
*/
// Choose Tracking Device in Editor
public enum EIndex
{
None = -1,
Hmd = (int)OpenVR.k_unTrackedDeviceIndex_Hmd,
Device1,
Device2,
Device3,
Device4,
Device5,
Device6,
Device7,
Device8,
Device9,
Device10,
Device11,
Device12,
Device13,
Device14,
Device15
}
public EIndex index;
void Update()
{
//Use chosen Tracker
var i = (int)index;
//Collect delta rotation and displacement between Tracker and Accessory
Vector3 delta_displacement = new Vector3(dX, dY, dZ);
Quaternion delta_rotation = Quaternion.Euler(roll, yaw, pitch);
//Get current Tracker pose
Vector3 tracker_position = SteamVR_Controller.Input(i).transform.pos;
Quaternion tracker_rotation = SteamVR_Controller.Input(i).transform.rot;
//Transform current Tracker pose to Accessory pose
GameObject.Find("Accessory").transform.rotation = tracker_rotation * delta_rotation;
GameObject.Find("Accessory").transform.position = tracker_position + (tracker_rotation * delta_rotation) * delta_displacement;
}
}
This is supposed correct the stance of the drawer in relation to the vive tracker. Here's the problem: Activating the script changes position and rotation auf the drawer the right way in the Scene Window if I start the Application. The game view and the vive however still show the old transform of the drawer, as if my accessory script had never happened. I never had such a difference between Scene and Game view on runtime. Maybe somebody knows why this is happening? I don't know if it's an issue related to Vive and the trackers or not.
If you need additional info, let me know!
Big thanks in advance, Adrian
Your answer
Follow this Question
Related Questions
transform.lookat not working? 0 Answers
Boss won't track player movement 2 Answers
UI Editor & Gizmos in Runtime 0 Answers
Track only closest enemy transform 1 Answer