门旋转问题时风量增加,如何修复?

时间:2015-09-28 05:12:24

标签: c# unity3d rotation

我有一个基本的汽车模型和一个风声。风已经发出,因此随着汽车加速而变得越来越大,但随着车门开得更宽,声音也越大。它在左门上工作得很好,但在右门上拧紧。我认为它与右门的旋转有关,首先它会在移动前大约90º,但随后当门打开时,它会超过360º然后再回到0°,继续旋转。这就是我认为搞砸了,但我不知道。如果这是问题,有人可以告诉我如何解决它,或者如果不是,那么告诉我实际上是什么问题,然后如何解决它?提前谢谢!

代码:

if(cameraIndex == 1){
        outsideCamera.enabled = false;
        driverCamera.enabled = true;
        passengerCamera.enabled = false;
        FPCamera.enabled = false;


        float driverVolume = 0.1f * (motor.speed / motor.topSpeed) + 0.1f;
        outsideCamera.GetComponent<AudioSource>().volume = 0f;
        driverCamera.GetComponent<AudioSource>().volume = driverVolume;
        passengerCamera.GetComponent<AudioSource>().volume = 0f;
        FPCamera.GetComponent<AudioSource>().volume = 0f;

        ambientSound.GetComponent<AudioSource>().volume = 0.5f;

        if(motor.ignitionIndex == 1){
            motor.engineSoundSource.volume = 0.5f;
            motor.hornSoundSource.volume = 0.8f;
        }


        if(leftDoor.clickCount == 1){
            driverCamera.GetComponent<AudioSource>().volume = driverVolume + ((leftDoor.transform.localEulerAngles.y) / 150) * ((motor.speed / motor.topSpeed) / 1.5f);
            if(motor.ignitionIndex == 1){
                motor.engineSoundSource.volume = 0.6f;
                motor.hornSoundSource.volume = 0.9f;
            }
        }

        //problem area below            

        if(rightDoor.clickCount == 1){
            driverCamera.GetComponent<AudioSource>().volume = driverVolume + ((((rightDoor.transform.localEulerAngles.y) - (210 + 150)) * -1) / 150) * (motor.speed / motor.topSpeed / 1.5f);
            if(motor.ignitionIndex == 1){
                motor.engineSoundSource.volume = 0.6f;
                motor.hornSoundSource.volume = 0.9f;
            }
        }

        activeCamera = driverCamera;

    }

1 个答案:

答案 0 :(得分:1)

是的,我认为这也是你的问题,因为当你刚刚减去90时它可能会给出一个负数量。

我不知道如何修复它,因为当门打开时我不知道它是如何通过度数的,但我建议只是调整你的代码。尝试添加90或从90减去角度而不是相反。

你减去90,因为在另一边它从90开始?然后它一直到91,92一直到180,然后它与音量相关联。因为这可能意味着你甚至不需要在另一侧减去90,只需反转它或其他东西。也许试试这个:http://docs.unity3d.com/ScriptReference/Quaternion.Inverse.html