简体   繁体   English

Unity2D-为什么对象绕X / Y轴而不是Z旋转

[英]Unity2D - Why does the object rotate around the X/Y axis rather than the Z

I am trying to rotate an object to face another in Unity 2D. 我正在尝试旋转对象以使其在Unity 2D中面向另一个对象。 However i am having some trouble wrapping my head around the way unity uses 2D transformations and most examples I can find are designed for 3D. 但是,我在围绕统一使用2D转换的方式时遇到了一些麻烦,我可以找到的大多数示例都是针对3D设计的。

Using the code below I can make the object rotate to face the right direction, however it also rotates the object so that it is the Z axis that is pointing towards it. 使用下面的代码,我可以使对象旋转以面向正确的方向,但是它也会旋转对象,使得Z轴指向该对象。 Ideally the object would rotate around the Z axis. 理想情况下,对象将绕Z轴旋转。

rigidbody2D.transform.LookAt(currentlyTargeted.transform.position);

Any guidance would be much appreciated. 任何指导将不胜感激。

确保正确旋转了对象在网格/精灵中的方向,或将对象放置在用于将旋转偏移到X / y轴的虚拟对象中

I had a similar issue recently with LookAngle - please notice these functions take two arguments (the second one defaults to Vector3.up) - what did the trick for me is to call LookAngle like this: 我最近在LookAngle遇到了一个类似的问题-请注意,这些函数带有两个参数(第二个参数默认为Vector3.up)-对我来说,窍门是这样调用Lo​​okAngle:

LookAngle(Vector3.forward, myCalculatedPositionsDifference)

Maybe it will also help in your case? 也许这对您也有帮助?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM