有關Kinect结合Unity3D引擎开发体感游戏(二)
@地瓜儿 你好,想跟你请教个问题:
依照您定義的我建立kinectMoving.cs
我建立一個terrain的scene, 拉入一個Hierarchy組件(如cubes, 內包含階層cube, 準備對應head, spine, ...)
拉入kinectPrefab,
連接好Kinect設備, 跑Kinect结合Unity3D引擎开发体感游戏(二)rainbowMan_v6正常,
但跑自訂的scene後, cubes都不會動, 求助
// kinectMoving .cs
using UnityEngine;
using System.Collections;
using Kinect;
public class kinectMoving : MonoBehaviour {
public int state = 0;
public float moveSpeed = 12f;
public SkeletonWrapper sw;
public GameObject Hip_Center;
public GameObject Spine;
public GameObject Head;
public GameObject Hand_Left;
public GameObject Hand_Right;
void Start () {
}
// Update is called once per frame
void Update () {
JuAction();
}
public void setHeroState(int newState)
{
int rotationValue = (newState - state) * 90;
Vector3 transformValue = new Vector3();
animation.Play("rainbowMan_v6A");
switch (newState)
{
case 0:
transformValue = Vector3.forward * 10; // Time.deltaTime;
break;
case 1:
transformValue = -Vector3.forward * 10; // Time.deltaTime;
break;
case 2:
transformValue = Vector3.left * 10; // Time.deltaTime;
break;
case 3:
transformValue = -Vector3.left * 10; // Time.deltaTime;
break;
}
transform.Rotate(Vector3.up, rotationValue);
transform.Translate(transformValue * moveSpeed, Space.World);
state = newState;
}
private void JuAction()
{
Vector3 hip=Hip_Center.transform.position;
Vector3 handRight = Hand_Right.transform.position;
Vector3 handLeft = Hand_Left.transform.position;
Vector3 spine = Spine.transform.position;
Vector3 head = Head.transform.position;
bool flag;
if (handLeft.y > spine.y - 0.1 || handRight.y > spine.y - 0.1)
flag = true;
else
flag = false;
if (flag)
{
if (head.x < spine.x - 0.2)
{
setHeroState(0);
Debug.Log("Left ... ...");
}
if (head.x > spine.x - 0.2)
{
setHeroState(1);
Debug.Log("Right ... ...");
}
if (head.z < spine.z - 0.1)
{
setHeroState(2);
Debug.Log("Front ... ...");
}
if (head.z > spine.z - 0.1)
{
setHeroState(3);
Debug.Log("Back ... ...");
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然的 这个是需要与人物的骨骼绑定的 你后面用的没有这些绑定 后面动的话 可以用别的方法