how i make float move from 0 to 1 smoothly because i want to make car turbo and when releases make bov sound

hi im majd

i was using unity and im c# dev so i want now to move to unreal
so my question
how to make turbo if u press hold throttle of vehicle float moves from 0 to 1 and sound start move pitch like whoosshh and if you release it should get from 1 to 0 and make bov stustu sound (Turbo system)

i mean here in unreal for me little bit hard

but im trying my best to do the code and i couldnt

this my c# code if u can convert it to example blueprint code thanks for anyone want to help me!

this my unity c# turbo system

public class Turbo : MonoBehaviour
{
	private float throttleMultipler;

	public AudioSource turboLoopSound;

	public AudioSource turboSounds;

	public float MAX_TURBO_COEFF;

	public float turboCoeff;

	public float turboValue;

	public bool turboIsActive;

	public bool turboEnabled;

	private void Start()
	{
		turboLoopSound.volume = 0f;

		
	}
	public float verticalInput;

	private void Update()
	{
		verticalInput = Input.GetAxis ("Vertical");
		if (verticalInput > 0 * Time.deltaTime)
            {
				turboValue += 1f * Time.deltaTime;
				turboValue = Mathf.Min(turboValue, 1.5f);
				turboIsActive = true;
				turboCoeff = MAX_TURBO_COEFF * turboValue;
				turboLoopSound.volume = turboValue * 0.40f;
				turboLoopSound.pitch = Mathf.Lerp(0.8f, 1.3f, turboValue);
				turboSounds.volume = Mathf.Lerp(turboSounds.volume, 0f, 3.5f * Time.deltaTime);
				return;
            }

			if (turboIsActive && turboValue > 0.8f)
			{
				turboSounds.volume = 1f;
				turboSounds.Play();
				turboSounds.pitch = UnityEngine.Random.Range(0.85f, 1.15f);
			}
			turboCoeff = 0f;
			turboIsActive = false;
			turboValue = Mathf.Lerp(turboValue, 0f, 10f * Time.deltaTime);
			turboLoopSound.volume = 0f;
		

	}

There are many ways you can handle this. Unreal has a class called FMath which has various interpolation methods like lerp or FInterpInto. Similar methods are also availables for vectors/rotators/matrices/quaternions/…

In your case you can define a float variable called InterpolationDuration (or any other name) and another float called CurrentTimeProgress, then at each tick if some condition is met you add delta time to CurrentTimeProgress or if the condition is not met subtract it and then use FMath::Clamp to limit it between 0 and InterpolationDuration. Also all of these methods are accessible in blueprints with the same name.

After changing the CurrentTimeProgress you Just use lerp between your turbo value and 0 and put CurrentTimeProgress/InterpolationDuration as the alpha parameter.

for the sound there is this whole meta sound system you can use but it is kind of hard to explain here. You can check the official UE documentation on it here:

hmm is this work for ue4?

thanks

meta sound was introduced in UE 5. If you are just migrating to UE I would say there is no reason to use UE4 over UE5 but in case you insist on using UE4 there is a system called sound cue which should be still capable enough to do the job.

You’d need an actor/pawn for your car. You’d have your input bindings there. I’d recommend moving to UE5 as it’s simpler to do with Enhanced Input. You’d have to watch a tutorial. It’s more than I can describe here, but is really easy once you’ve tried it. Or you can just track the input directly to get you started and store the value in your car actor.

Add a UAudioComponent to your car actor and add your method to your car actor that is called from the Tick() function IF turboIsActive is true.

There’s UAudioComponent::SetPitchMultiplier() to change the pitch.

You could also derive UAudioComponent (call it WooshComponent) and add the Update code to your Tick() method directly. Just put “if (!turboIsActive) return;” at the top. The Tick() method has your delta time, but it’s time between frames, not total time as your method seems to want though I’m not certain that’s correct either.

Also, this is sketchy code
if (verticalInput > 0 * Time.deltaTime)

I will do first car raycast physics then i will do this turbo system
thanks for anyone helps me !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.