Home Game Development unity – How to vary pitch worth based on airplane propeller rotation velocity?

unity – How to vary pitch worth based on airplane propeller rotation velocity?

0
unity – How to vary pitch worth based on airplane propeller rotation velocity?

[ad_1]

It’s like making the propeller with the pitch sound engine beginning impact.

I’ve some airplane with a propeller and a script connected to the propeller making the propeller begin spinning when operating the sport from gradual to max velocity.

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
 
public class Spin : MonoBehaviour
{
    public float RotationSpeed = 1;
 
    // Start is named earlier than the primary body replace
    void Start()
    {
 
    }
 
    // Update is named as soon as per body
    void Update()
    {
        remodel.Rotate(0, 0, RotationSpeed, Space.Self);
 
        if (RotationSpeed < 10)
        {
            RotationSpeed += 1f * Time.deltaTime;
        }
    }
}

on empty gameobject i added audio supply and dragged to it a mp3 sound impact of propeller and in addition connected to the empty gameobject a script and dragged to the script the propeller object with the Spin script :

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
 
public class AudioExample : MonoBehaviour
{
    public int startingPitch = 4;
    public int decreaseAmount = 5;
    public Spin spin;
 
    personal AudioSource _audioSource;
 
    void Start()
    {
 
        _audioSource = GetComponent<AudioSource>();
        _audioSource.pitch = startingPitch;
    }
 
    void Update()
    {
 
        if (_audioSource.pitch > 0)
        {
            _audioSource.pitch += Time.deltaTime * startingPitch / spin.RotationSpeed;
        }
    }
}

Screenshot of the propeller object :

propeller

and a screenshot of the empty gameobject with the audio supply :

empty gameobject

The pitch within the audio supply by default begin at worth 1 and be modified between the values -3 and three.
The rotation velocity within the Spin script is in different items.

what i need to do is when i am operating the sport and the propeller begin rotating slowly to max velocity that the pitch automated will change it is worth based on the propeller rotation velocity so the pitch sound and the propeller rotation can be sync.

The script AudioExample as it’s now making the pitch worth to be a lot over the three worth over 10.
The calculation within the AudioExample script is mistaken and i am undecided the way to do it :

_audioSource.pitch += Time.deltaTime * startingPitch / spin.RotationSpeed;

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here