How to move an object left and right in unity using trackhat opentrack headtracker ?
Hello!! Currently I have developed a game called 2d space shooter and in that there is an energy shield which should be controlled with the track hat head tracker using "FaceTrackNoIR App". I have already integrated the dll file in unity and I have this code:
In this code I want the logic to be changed to controlling the shield using head tracker (only with the yaw movements). Can someone tell how to do it please? As of now, I am using vertical axes control in FixedUpdate method.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class ShieldControl : MonoBehaviour
{
public float shieldspeed;
private Transform shield;
public float speed;
public float maxBound, minBound;
[StructLayout(LayoutKind.Sequential)]
public struct FreeTrackData
{
public int dataid;
public int camwidth, camheight;
public Single Yaw, Pitch, Roll, X, Y, Z;
public Single RawYaw, RawPitch, RawRoll;
public Single RawX, RawY, RawZ;
public Single x1, y1, x2, y2, x3, y3, x4, y4;
}
[DllImport("FreeTrackClient64")]
public static extern bool FTGetData(ref FreeTrackData data);
public float Yaw = 0F;
public float Pitch = 0F;
public float Roll = 0F;
public float X = 0F;
public float Y = 0F;
public float Z = 0F;
public float RawYaw = 0F;
public float RawPitch = 0F;
public float RawRoll = 0F;
public float RawX = 0F;
public float RawY = 0F;
public float RawZ = 0F;
public float x1 = 0F;
public float y1 = 0F;
public float x2 = 0F;
public float y2 = 0F;
public float x3 = 0F;
public float y3 = 0F;
public float x4 = 0F;
public float y4 = 0F;
private ShieldControl.FreeTrackData trackData;
private static float direction;
// Start is called before the first frame update
void Start()
{
shield = GetComponent<Transform>();
trackData = new ShieldControl.FreeTrackData();
}
void FixedUpdate()
{
float h = Input.GetAxis("Vertical");
if (shield.position.x < minBound && h < 0)
h = 0;
else if (shield.position.x > maxBound && h > 0)
h = 0;
shield.position += Vector3.right * h * speed;
}
// Update is called once per frame
void Update()
{
if (!ShieldControl.FTGetData(ref trackData))
{
Debug.Log("FTGetData returned false. FreeTrack likely not working.");
return;
}
ShieldControl.FTGetData(ref trackData);
Yaw = trackData.Yaw;
Pitch = trackData.Pitch;
Roll = trackData.Roll;
X = trackData.X;
Y = trackData.Y;
Z = trackData.Z;
RawYaw = trackData.RawYaw;
RawPitch = trackData.RawPitch;
RawRoll = trackData.RawRoll;
RawX = trackData.RawX;
RawY = trackData.RawY;
RawZ = trackData.RawZ;
x1 = trackData.x1;
y1 = trackData.y1;
x2 = trackData.x2;
y2 = trackData.y2;
x3 = trackData.x3;
y3 = trackData.y3;
x4 = trackData.x4;
y4 = trackData.y4;
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make fast a coroutine 1 Answer
Compiler error 0 Answers
Jittery background when implementing parallax effect 1 Answer
Problem getting components in loaded scene 0 Answers
Instantiating A group of platform and moving them down 0 Answers