简体   繁体   English

物体不绕其轴旋转

[英]Object not rotating around its axis

I have a gun consisting of two parts (1 is handle, 2 is nozzle). 我有一个由两部分组成的枪(1个是手柄,2个是喷嘴)。 I want to rotate the nozzle when I shoot the target. 我想在射击目标时旋转喷嘴。

我想像这样旋转喷嘴

I am using following code of line inside my fire function 我在fire函数中使用了以下代码

gunNozzle.transform.Rotate(0, 0, 10);

It is increasing the rotation value, but the result is different. 它正在增加旋转值,但结果是不同的。 Here is complete function: 这是完整的功能:

void Update()
{
    if (Input.GetKeyDown(KeyCode.P))
    {
        isOut = true;
    }
    if (isOut)
    {     
        playerAnim.CrossFade("gunplays", 0.03f);
        gunNozzle.transform.Rotate(0, 0, 10);
        audioSource.Play();
        GameObject cloneArrow = (GameObject)Instantiate(theArrow, thePos, Quaternion.identity);
        cloneArrow.transform.position = thePos;
        cloneArrow.transform.rotation = this.transform.rotation;
        isOut = false;
    }
}

It seems to be a simple thing, but I am stuck. 这似乎很简单,但我被困住了。

Here is the result: 结果如下:

以下是上述代码的结果

Your parameters to transform.Rotate don't looks correct to me. 你的transform.Rotate参数看起来不对我。 Should be something like 应该是这样的

gunNozzle.transform.Rotate(Vector3.right * Time.deltaTime);

Nb: Vector direction might be wrong in my example. Nb:在我的例子中,矢量方向可能是错误的。

尝试在Rotate()中包含Space.Self或Space.World

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

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