c# - 在 Unity 中使用 Kinect 身体关节位置仅允许 x 位置随时间变化
问题描述
伙计们,我正在制作一个无尽的跑步游戏,它将通过身体位置来控制。
我正在尝试使用 Kinect 传感器将角色向左或向右(x 轴)移动到我的身体位置。角色可以自由地向前移动(z 轴)Time.deltaTime
。角色CharacterController
附有剧本。移动代码如下:
CharacterController controller;
KinectManager kinectManager;
float speed = 5.0f
Vector3 moveDir;
void Update()
{
moveDir = Vector3.zero;
moveDir.z = speed;
moveDir.x = kinectManager.instance.BodyPosition * speed;
//controller.Move(moveDir * Time.deltaTime);
controller.Move(new Vector3 (moveDir.x, 0, moveDir.z * Time.deltaTime));
}
该语句controller.Move(moveDir * Time.deltaTime);
不断向左或向右移动字符,因为 x 位置正在增加,Time.deltaTime
所以我想限制它,我将其更改为controller.Move(new Vector3 (moveDir.x, 0, moveDir.z * Time.deltaTime));
.
现在发生的事情是角色被卡在同一个位置。我可以随着身体位置向左或向右移动,但不能向前移动。我在这里想念什么?
请帮忙。
解决方案
识别问题
首先尝试仔细观察您的轴,您的游戏对象 y 轴在哪里,因为您为其分配了 0 值。下面的代码将帮助您找到问题并解决它。
解决方案
void Update()
{
if (controller.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection = moveDirection * speed;
if (Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
推荐阅读
- python - 如何在熊猫中进行精确的十进制数计算?
- c++ - 如何在 Qt 中复制和粘贴自定义对象
- javascript - Fullcalendar.io 如何从标题中截取“上一个”和“下一个”
- ios - 在已弃用的 NSURLConnectionDelegate 上报告了 MITM 攻击
- javascript - 在 AWS Lambda 中使用 NodeJS 将 Woocommerce API 函数更改为异步/等待
- c++ - 在Qt中进行多次图形更改时如何最小化屏幕闪烁?
- types - 函数类型:不能用 abi.decode 解码
- java - 使用 OAuth 1.0 请求 Twitter api
- opendaylight - Opendaylight neon:旧 l2switch 功能的替代品
- python - 如何使python循环“不等待”完成上一个命令?