英文:
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.right
或new 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论