简体   繁体   English

如何以跳跃动作统一抓取和移动游戏对象

[英]How to grab and move gameObjects in unity with leap motion

I am making a project with unity and leap motion, but I'm new with leap. 我正在以团结和跳跃的姿态进行项目,但是我是跳跃的新手。 I'm trying to move gameObjects but when I add the property of rigidBody to it and touch it with the handmodels it flies away, how do I avoid this? 我正在尝试移动gameObjects,但是当我向其中添加刚性实体的属性并使其与手模型接触时,它就会飞走,如何避免这种情况?

Because the default physics hands Leap provides in its core assets are interpreted as "kinematic," they basically have infinite mass. 由于Leap在其核心资产中提供的默认物理手被解释为“运动学”,因此它们基本上具有无限的质量。 Objects are flying away when you try to grab or touch them because the underlying physics solver is trying to figure out what happens when you crush a perfectly rigid body (hence "Rigidbody") between two other rigidbodies of infinite mass... The solver winds up with huge velocities and as a result you get behavior that looks weird and feels bad. 当您尝试抓住或触摸物体时,物体正在飞走,因为底层的物理求解器试图找出当您在另外两个无限质量的刚体之间挤压一个完美的刚体(因此称为“刚体”)时会发生什么。速度很快,结果您的行为看起来很怪异,感觉很糟糕。

There's some fancy math (Kabsch solving) and real-time physics (soft, non-rigid contact behavior) involved in make touching and grasping objects feel good, so you're probably just going to want to download Leap's Interaction Engine, which does all of that for you! 有一些花哨的数学(卡布斯求解)和实时物理(软,非刚性接触行为)可以使触摸和抓握物体感觉良好,因此您可能只想下载Leap的Interaction Engine,即可完成所有操作为您服务!

Make sure you have the latest "Core Assets" from the main developer resource page , and you can find the "Interaction Engine" on that same page. 确保您在开发人员主页上拥有最新的“核心资产”,并且可以在同一页面上找到“交互引擎”。

Download those packages and import them into Unity, then your workflow will basically work thusly: 下载这些软件包并将其导入Unity,然后您的工作流程将基本正常运行:

  • Find the InteractionManager prefab in the InteractionEngine folder, and drag it into your scene. 在InteractionEngine文件夹中找到InteractionManager预制件,然后将其拖到场景中。 This object just does necessary bookkeeping for the interaction system. 这个对象只是为交互系统做必要的簿记工作。
  • Remove those RigidRoundHands you were using from the Hand Controller, and add the Interaction Brush Hands in the InteractionEngine folder instead. 从“手形控制器”中删除您正在使用的那些RigidRoundHands ,然后将“ Interaction Brush Hands”添加到“ InteractionEngine”文件夹中。 These hands have extra physics logic baked in that prevents interactions from being explosive the way you were describing. 这些指针具有额外的物理逻辑,可防止交互以您描述的方式爆发。
  • Add an InteractionBehaviour component to any object you would like to be able to touch or pick up. 将InteractionBehaviour组件添加到您希望能够触摸或拾取的任何对象。

From there, you should be good to go. 从那里开始,您应该会很好。 If something stops working at any step, you can check out the Interaction Engine 101 example on the developer page; 如果任何步骤都停止工作,则可以在开发人员页面上签出Interaction Engine 101示例; it's an open-source Unity project with a working implementation of the latest Interaction Engine. 这是一个开放源代码的Unity项目,其中包含最新交互引擎的有效实施。

I think you should move it using a Coroutine. 我认为您应该使用协同程序来移动它。 You can find more info here: https://docs.unity3d.com/Manual/Coroutines.html This should do the trick without much code. 您可以在这里找到更多信息: https : //docs.unity3d.com/Manual/Coroutines.html这应该可以在不需要太多代码的情况下完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM