Unity transform.LookAt in only one axis

倖福魔咒の 提交于 2019-12-12 03:57:25

问题


I've been working on a game and it's going really nice. Got some help from here and I need it again. So I'm making a 2D top-down shooter and I need my enemy to look at the player, and obviously the enemy will rotate in all axis and thus being invincible or will look really weird. So, how do I make it rotate only in the Z axis ? Also if you are going to provide and answer I need it done in UnityScript.


回答1:


You just need to set a fixed value at the axis that you don't want to move.

Example, LookAt moving only the Z axis:

var adjusted= target;
adjusted.x = 0;
adjusted.y = 0;
transform.LookAt(adjusted);

If you had made a quickly search on google, you would find it.



来源:https://stackoverflow.com/questions/35348520/unity-transform-lookat-in-only-one-axis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!