Unity transform.LookAt仅在一个轴上 [英] Unity transform.LookAt in only one axis

查看:1137
本文介绍了Unity transform.LookAt仅在一个轴上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一款游戏,而且进展非常顺利.从这里得到了一些帮助,我再次需要它.所以我要制作一个2D自上而下的射击游戏,我需要我的敌人看着玩家,很明显,敌人会在所有轴上旋转,因此是无敌的,或者看起来很怪异.那么,如何使它仅在Z轴上旋转?另外,如果您要提供并回答我需要在UnityScript中完成.

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.

推荐答案

您只需要在不想移动的轴上设置一个固定值即可.

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

例如,LookAt仅移动Z轴:

Example, LookAt moving only the Z axis:

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

如果您在Google上进行了快速搜索,就会找到它.

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

这篇关于Unity transform.LookAt仅在一个轴上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆