unity3d中怎么将position的值从local改为world
时间: 2024-02-13 17:59:41 浏览: 43
在Unity3D中,可以使用`Transform.TransformPoint()`方法将本地坐标系下的`position`转换为世界坐标系下的`position`。具体的实现方式如下:
```csharp
Vector3 worldPosition = transform.TransformPoint(localPosition);
```
其中,`transform`表示当前游戏对象的变换组件,`localPosition`表示当前游戏对象相对于父级对象的本地坐标系下的位置向量,`worldPosition`表示转换后的世界坐标系下的位置向量。
相关问题
unity 中 SkinnedMeshRenderer mesh world position change to local position
To change the world position of a SkinnedMeshRenderer mesh to local position, you can use the Transform.InverseTransformPoint method. Here's an example:
```
// Get the world position of the mesh
Vector3 worldPosition = skinnedMeshRenderer.transform.TransformPoint(skinnedMeshRenderer.sharedMesh.vertices[0]);
// Convert the world position to local position
Vector3 localPosition = skinnedMeshRenderer.transform.InverseTransformPoint(worldPosition);
```
In this example, we're getting the world position of the first vertex in the shared mesh of the SkinnedMeshRenderer. We then use the Transform.InverseTransformPoint method to convert the world position to local position.
You can use this method to convert any world position to local position relative to the SkinnedMeshRenderer's transform.
unity中localPosition生成的坐标为什么不对
Unity中的localPosition是物体相对于其父物体的位置坐标,而不是相对于世界坐标系的位置坐标。如果你在使用localPosition时出现了错误的坐标,可能是因为你的父物体的位置或旋转发生了改变,从而导致了子物体的位置偏移。另外,如果你正在使用某些组件(如Transform),它们可能会影响物体的位置。如果你仍然遇到问题,建议检查你的代码和场景中的物体层级结构。