public Vector3 GridToGlobal(IVector3 gridPos)
{
Vector3 globalPos = new Vector3(gridPos.x, gridPos.y, gridPos.z);
globalPos *= Scale;
globalPos = Container.transform.rotation * globalPos;
return globalPos;
}
现在,当我想进行反向操作时,如何将向量旋转到网格空间中?
public IVector3 GlobalToGrid(Vector3 globalPos)
{
globalPos -= Container.transform.position;
globalPos = Container.transform.rotation * globalPos; //this will obvIoUsly rotate in the wrong direction
globalPos /= Scale;
return new IVector3((int)Mathf.Round(globalPos.x), (int)Mathf.Round(globalPos.y), (int)Mathf.Round(globalPos.z));
}
有任何想法吗?
解决方法:
您可以使用Quaternion.Inverse()函数.这使反向旋转.所以应该扭转.
您可以通过以下方式使用它:
transform.rotation = Quaternion.Inverse(target.rotation);
来源:http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.Inverse.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。