【发布时间】:2019-05-05 14:32:39
【问题描述】:
我有一个缩放的火焰喷射器预制件,我想在武器点实例化它。我的其他预制件(例如简单的子弹和激光)使用相同的脚本可以很好地实例化,但是这个预制件的位置和角度很奇怪。如何解决这个问题?
这是处理角度和实例化的脚本:
public class FlameThrowerGun : MonoBehaviour
{
public GameObject theFlame;
bool isFiring = false;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
SetPlayerRotation();
if (Input.GetButtonDown("Fire"))
{
Shoot();
}
}
void SetPlayerRotation()
{
if (Input.GetKey(KeyCode.W))
{
transform.rotation = Quaternion.Euler(0, 0, 45);
}
else if (Input.GetKey(KeyCode.S))
{
transform.rotation = Quaternion.Euler(0, 0, -45);
}
else
{
transform.rotation = Quaternion.Euler(0, 0, 0);
}
}
void Shoot()
{
GameObject bullet_ = Instantiate(theFlame, transform.position, transform.rotation * Quaternion.Euler(0f, 0f, -90f));
Destroy(bullet_, 1.0f);
}
}
* Quaternion.Euler(0f, 0f, -90f) 被放在那里以正确的角度实例化火焰。
我想补充一点,火焰预制件已缩放到y=2 以获得所需的大小,而不是在预制件的边缘实例化,而是在中心实例化,这就是为什么我觉得它有这个奇怪的位置。
这里是当直射和斜射时,它们都不在玩家武器位置:
【问题讨论】:
-
我想这是因为精灵枢轴点。我认为你的角色精灵和火焰精灵都有中心轴点。这样你的火焰精灵位置(它的中心)设置为角色精灵位置(也是中心)。