Thursday, September 8, 2022
HomeGame Developmentunity - Learn how to change pitch worth in response to airplane...

unity – Learn how to change pitch worth in response to airplane propeller rotation velocity?


It is 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 working the sport from gradual to max velocity.

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
 
public class Spin : MonoBehaviour
{
    public float RotationSpeed = 1;
 
    // Begin is named earlier than the primary body replace
    void Begin()
    {
 
    }
 
    // Replace is named as soon as per body
    void Replace()
    {
        rework.Rotate(0, 0, RotationSpeed, Area.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 Begin()
    {
 
        _audioSource = GetComponent<AudioSource>();
        _audioSource.pitch = startingPitch;
    }
 
    void Replace()
    {
 
        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 wish to do is when i am working the sport and the propeller begin rotating slowly to max velocity that the pitch automated will change it is worth in response to the propeller rotation velocity so the pitch sound and the propeller rotation might 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 unsuitable and i am unsure how you can do it :

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

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments