简体   繁体   English

围绕游戏对象的多个轴旋转

[英]Rotate around multiple axis of a GameObject

I am creating a measure app for iOS using Unity.我正在使用 Unity 为 iOS 创建一个测量应用程序。 I was able to measure distance between 2 points and show it in a GameObject .我能够测量 2 点之间的距离并将其显示在GameObject This is what I have achieved so far: [.[Measure something on the floor.这是我到目前为止所取得的成就:[.[测量地板上的东西。 User looking at top][1]][1]用户查看顶部][1]][1]

[![Measure horizontally on vertical plane][2]][2] [![在垂直平面上水平测量][2]][2]

My update method is like this.我的更新方法是这样的。

    if(textObj.activeInHierarchy == true)
            {
                direction = pointTwo - pointOne;                    
                textObj.transform.right = direction; 

            }

textObj is the white color measure indicator. textObj是白色测量指标。 pointOne and pointTwo are the starting point and ending point of the line. pointOnepointTwo是直线的起点和终点。

  1. I want to show this measure indicator always readable to the user regardless of his position. But in my case(second picture), the indicator should be tilled towards the user around its X axis and its Z axis always should be perpendicular to the drawn line.Its Y axis should always face towards the inverse direction of camera.transform.forward.我想向用户显示此度量指示器始终可读,而不管他的 position。但在我的情况下(第二张图片),指示器应围绕其 X 轴向用户倾斜,其 Z 轴应始终垂直于绘制的线.它的Y轴应该始终朝向camera.transform.forward的反方向。 I tried adding我尝试添加

    textObj.transform.up = -arCamera.transform.forward;

before set the textObj.transform.right = direction;在设置textObj.transform.right = direction; but that doesn't change any.但这并没有改变。 But you can see in Apple Measure app the distance indicator is always readable to the user regardless of his position. How can I achieve this?但是您可以在 Apple Measure 应用程序中看到距离指示器始终对用户可读,无论他的 position 是什么。我怎样才能做到这一点? Please help me.请帮我。

Thanks: [1]: https://i.stack.imgur.com/OQnmA.png [2]: https://i.stack.imgur.com/Hxwln.png感谢: [1]: https://i.stack.imgur.com/OQnmA.png [2]: https://i.stack.imgur.com/Hxwln.png

You can try this method: https://docs.unity3d.com/ScriptReference/Transform.LookAt.html你可以试试这个方法: https://docs.unity3d.com/ScriptReference/Transform.LookAt.html

In you case you want the text object to look at the camera.在您的情况下,您希望文本 object 看着相机。 The second parameter is a Vector specifying the upward direction, using the default value of Vector3.up it should work for you.第二个参数是一个指定向上方向的 Vector,使用默认值Vector3.up它应该适合你。

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

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