相对位置(相对于另一个对象)在Unity 3D中

huangapple go评论61阅读模式
英文:

Relative Position (to another object) in Unity 3D

问题

我希望一个物体相对于另一个游戏对象在3D单位中向右移动1个单位,因为另一个游戏对象的方向不同,这会干扰坐标系统。例如,当物体面向北时,右侧是x。但是当物体面向东时,右侧是z。有解决方法吗?

我尝试过

obj.transform.position + obj.transform.right * x

还尝试了TransformDirection。它们都没有起作用。

英文:

I want an object to be placed 1 unit to the right with respect to another game object unit 3d, since the other game object have different orienetation and that messes up with the cordindate system. For example, when the object is facing North, right is x. But when the object is facing East, right is z. Is there a solution to this?

I tried

obj.transform.position +obj.transform.right*x

also tried TransformDirection. They did not work.

答案1

得分: 1

如果您不想受到方向的影响,只需使用Vector3.rightnew Vector(1,0,0)作为偏移量。

obj.transform.position + Vector3.right * x

英文:

If you don't want to be affected by orienetation, then just use the Vector3.right or new Vector(1,0,0) as the offset.

obj.transform.position + Vector3.right * x

huangapple
  • 本文由 发表于 2023年5月17日 11:41:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268409.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定