[英]Unity move of child object
我正在創建一個小型演示,其中對象應根據來自 FOVE VR 耳機的眼動儀數據移動。
當我嘗試移動我的兩個對象(“Gaze Responder - Target”和“Gaze Responder - Fixation”)時:它們不移動,碰撞器停止工作。
我在 Unity3d (2017.4.40f1) 中有以下層次結構
以下代碼附加到 GazeContingenVisualField
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VisualField_test : FOVEBehavior
{
private GameObject Target;
private GameObject Fixation;
private GameObject TargetGazeObj;
private GameObject FixationGazeObj;
private Collider collider_Fixation;
private Collider collider_Target;
private float TimeShowFix;
private float T_ShowStim = 5.1f;
private float T_TimeOut = 10.0f;
private float[] StimPos_H_deg = { 0, 0, 0, 10, -10, 10, 10, -10, -10 };
private float[] StimPos_V_deg = { 0, 10, -10, 0, 0, 10, -10, 10, -10 };
private float[] StimPos_H = new float[100];
private float[] StimPos_V = new float[100];
private Material materialTarget;
private Material materialFixaton;
public enum StateTypes { WaitStart, TargetOn, TargetTimeOut, TargetSeen };
public StateTypes CurrentState = StateTypes.WaitStart;
public int idx_stimpos = 0;
// Use this for initialization
void Start()
{
for (int i = 0; i < StimPos_H_deg.Length; i++)
{
StimPos_H[i] = Mathf.Tan(StimPos_H_deg[i] / 180.0F * Mathf.PI) * 20.0F;
StimPos_V[i] = Mathf.Tan(StimPos_V_deg[i] / 180.0F * Mathf.PI) * 20.0F;
}
Target = transform.Find("Gaze Responder - Target").gameObject;
Fixation = transform.Find("Gaze Responder - Fixation").gameObject;
TargetGazeObj = Target.transform.Find("Gazable object").gameObject;
FixationGazeObj = Fixation.transform.Find("Gazable object").gameObject;
materialTarget = TargetGazeObj.GetComponent<Renderer>().material;
materialFixaton = FixationGazeObj.GetComponent<Renderer>().material;
collider_Fixation = FixationGazeObj.GetComponent<Collider>();
collider_Target = TargetGazeObj.GetComponent<Collider>();
materialTarget.DisableKeyword("_EMISSION");
materialFixaton.EnableKeyword("_EMISSION");
materialFixaton.SetColor("_EmissionColor", Color.green);
}
// Update is called once per frame
void Update()
{
switch (CurrentState)
{
case StateTypes.WaitStart:
if (FoveInterface.Gazecast(collider_Fixation))
{
CurrentState = StateTypes.TargetOn;
TimeShowFix = Time.time;
materialFixaton.EnableKeyword("_EMISSION");
materialFixaton.SetColor("_EmissionColor", Color.white);
}
break;
case StateTypes.TargetOn:
if (FoveInterface.Gazecast(collider_Target))
{
CurrentState = StateTypes.TargetSeen;
materialTarget.EnableKeyword("_EMISSION");
materialTarget.SetColor("_EmissionColor", Color.yellow);
}
else if (Time.time <= TimeShowFix + T_ShowStim)
{
materialTarget.EnableKeyword("_EMISSION");
materialTarget.SetColor("_EmissionColor", Color.white);
}
else
{
materialTarget.DisableKeyword("_EMISSION");
}
if (Time.time >= TimeShowFix + T_TimeOut)
{
CurrentState = StateTypes.TargetTimeOut;
}
break;
case StateTypes.TargetTimeOut:
idx_stimpos = (idx_stimpos +1) % StimPos_H.Length ;
materialTarget.DisableKeyword("_EMISSION");
Target.transform.localPosition = new Vector3(StimPos_H[idx_stimpos], StimPos_V[idx_stimpos], 0.0f);
CurrentState = StateTypes.TargetOn;
TimeShowFix = Time.time;
break;
case StateTypes.TargetSeen:
idx_stimpos = (idx_stimpos + 1) % StimPos_H.Length;
materialTarget.DisableKeyword("_EMISSION");
Fixation.transform.localPosition = Target.transform.localPosition;
Target.transform.localPosition = new Vector3(StimPos_H[idx_stimpos], StimPos_V[idx_stimpos], 5.0f);
CurrentState = StateTypes.TargetOn;
TimeShowFix = Time.time;
break;
}
}
}
using Fove.Unity;
using UnityEngine;
public class FOVEBehavior: MonoBehaviour
{
private static FoveInterface foveInterface;
public static FoveInterface FoveInterface
{
get
{
if (foveInterface == null)
{
// returns the first FoveInterface found here but you should adapt this code to your game
// especially in the case where you could have no or several FoveInterface in your game
foveInterface = FindObjectOfType<FoveInterface>();
}
return foveInterface;
}
}
}
我不確定 FOVE 是如何工作的,但它是否以某種方式重置了“-Target”對象變換?
當我使用 AR 時,一些游戲對象(目標)無法移動,因為它們的變換是由庫處理的,並且試圖這樣做會導致各種奇怪的問題。
也許你想要移動的是實際的“Gazable Objects”(我知道這是 VR,但也許是同一個問題)。
如果有的話,在最后一個案例語句中,您將本地的固定 position 設置為 TargetGazeObj 的本地 position,但它們的坐標參考可能不同,因此您可能希望在那里使用全局 Z4757FE07FD492A38BE0EAZA760ED。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.