Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by sriakella · Mar 03, 2021 at 10:39 PM · unity 2d

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges