【问题标题】:Unity Transform Point returns wrong valueUnity 变换点返回错误值
【发布时间】:2019-08-29 15:10:19
【问题描述】:

我有这个层次结构:

ScriptHandler <= this have script

MultiShape <= taking sides[] from here 
     local_axis_1 <= I need Global coordinates of this
     local_axis_2 <= side[i] have this as GameObject field 
          Projectile1 
          Projectile2

我需要 TransformPoint,以获取全局坐标中 localAxises 的位置。但是,我试图做的一切都失败了:检查代码。

那么如何获取这个游戏对象的全局位置呢?

有些人建议这样做:sides[i].transform.parent.TransformPoint(sides[i].transform.position)

这个东西效果很好,然后MultiShape有旋转(0,0,0)。但后来我改变了 z 的旋转,它不起作用。

//this dont work anytime, even rotation is 0,0,0
ShapeSide[] sides = mainMesh.shapeSides;
Vector3 pos = sides[i].localAxis.transform.TransformPoint(sides[i].localAxis.transform.position);

//this works only then rotation is 0,0,0
ShapeSide[] sides = mainMesh.shapeSides;
Vector3 pos = sides[i].localAxis.transform.parent.TransformPoint(sides[i].localAxis.transform.position);

【问题讨论】:

  • transform.position 已经是全球定位。
  • @Draco18s 哈哈,它真的很管用.....发送答案,我选择它

标签: c# unity3d transform


【解决方案1】:

Transform.position已经是全局位置

Transform 的世界空间位置。

没有理由将此值从本地空间转换为世界空间。

【讨论】:

    猜你喜欢
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2011-08-15
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多