旋转时固体物体的持久角度 [英] Persisting angle of solid objects while rotating

查看:188
本文介绍了旋转时固体物体的持久角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是UnityOculus的新手.我有一堆图像(它们的路径和其他信息是Oculus Touch在该房间内移动这些图像.

I am new to Unity and Oculus. I have a bunch of images (their path and other information are loaded from a JSON file) which I am trying to render in a VR room. And want to give the user an experience that he can move these images within that room using Oculus Touch.

我放置了一个Empty Object,其中包含一个通过JSON和 负责将图像加载到Sprite中.

I placed an Empty Object which has a script that iterates through JSON and creates a prefab object (which has Rigid body,Box Collider and OVRGrabbable -so that it can be grabbed in VR, components). Moreover this prefab object has a script which is responsible to load images in a Sprite.

什么在起作用?

图像正在渲染,可以被抓取和移动.

Images are getting rendered and can be grabbed and moved.

哪些功能无法正常工作?

我遵循了教程,并且如图所示,立方体的角度保持不变挺好的.但是,当抓取并旋转图像时,它不会持续存在,而是其侧角.如下图所示:

I followed this tutorial, and as shown here angles of the cube are persisted pretty fine. But when an image is grabbed and rotated, it doesn't persist it's side angles. As shown in following image:

问题

有什么办法可以解决它?我试图在网上寻找它,但是由于我是Unity的新手,所以我不确定我到底缺少什么.

Is there any way that I could fix it? I tried to look for it online but as I am new to Unity I am not quite sure what exactly I am missing.

任何线索将不胜感激.

推荐答案

我认为问题出在您的层次结构中.您的Images游戏对象(DisplayImage的父对象)的缩放比例为(1.88,1,1).尝试旋转其父对象在Unity中缩放比例不一致的子对象会给您带来时髦的结果.尝试将Images对象的比例重置为(1,1,1),看看是否有帮助.

I think the problem lies in your hierarchy. Your Images game object (the parent of your DisplayImage) has a scale of (1.88,1,1). Trying to rotate child objects whose parent object have non-uniform scale in Unity gives you funky results. Try resetting the scale of your Images object to (1,1,1) and see if that helps.

由于父母/孩子"关系的性质而发生此行为.孩子的坐标系是相对于其父母的.我们可以将其视为为孩子定义坐标系的父母.这就是我们所说的本地空间.因此,当我们在父对象上执行任何线性变换时,就像我们在子对象用来定义其方向的整个父坐标系统上执行它们一样.因此平移父对象将使其所有子对象一起移动,因为我们的整个局部坐标空间都已与父对象一起移动.请注意,我们的子代仍将具有相同的localPosition,但是其全局position将会更改.

This behaviour occurs because of the nature of the "parent/child" relationship. The child's coordinate system is relative to it's parents. We can think of it as the parent defining a coordinate system for our children. This is what we call local space. So, when we perform any linear transformations on the parent, it's like we're performing them on the whole parent coordinate system that our children are using to define their orientation. So translating the parent will move all of its children with it, because our whole local coordinate space has moved with the parent. Note that our children will still have the same localPosition, but their global position will have changed.

相同的逻辑适用于缩放和旋转.旋转父级实质上会旋转我们的孩子正在使用的整个坐标空间,使其围绕父级的中心点旋转(这将是局部空间中的点(0,0,0)).这样,所有子项都将被旋转,就好像它们是父对象的扩展一样.

The same logic applies to scaling and rotation. Rotating the parent essentially rotates the whole coordinate space that our child is using around the center point of the parent (which would be the point (0,0,0) in local space). So all children would then be rotated as if they were an extension of the parent object.

在我们的情况下,我们缩放了父级,因此缩放了用于定义子对象的整个坐标系.这意味着使用父对象坐标空间的任何内容也将根据父对象的比例进行缩放.在我们的情况下,父级按(1.88,1,1)进行缩放.因此,附加到父对象的所有内容也沿父对象的X轴缩放了1.88 ,从而在屏幕截图中看到了怪异的效果.尽管旋转了我们的子对象,但它仍沿父对象的X轴缩放.

In our situation we've scaled our parent, thus scaling the whole coordinate system we use to define our child object. This means that anything using the parent's coordinate space will also be scaled according to the parent's scale. In our situation, the parent was scaled by (1.88,1,1). So everything attached to the parent was also scaled along the parent's X-Axis by 1.88, resulting in the weird effect seen in your screenshots. Despite rotating our child object, it's still scaled along the parent's X-axis.

(与此官方文档的链接链接.)

解决方案是将线性变换尽可能深地应用到层次结构中.在这里,不是缩放父级,而是缩放子级.如果父对象需要缩放,或者它的缩放比例是动态变化的,则另一种解决方案是从子/子层次结构中删除子对象,并基于脚本中旧父对象的变换来操纵其变换.在这种情况下,您可以将未链接的孩子的位置和旋转设置为父母的位置和旋转,但是忽略比例.

The solution to this is to apply your linear transformations as deep in the hierarchy as possible. Here, instead of scaling the parent, scale the child. If the parent object needs to be scaled, or its scale changes on the fly, another solution would be to remove the child from the parent/child hierarchy and manipulate its transform based on the old parent's transform in a script. In this case you could set the unlinked child's position and rotation to the parent's position and rotation, but ignore the scale.

这篇关于旋转时固体物体的持久角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆