Question about Area3D signal

Godot Version

4.3.Stable

Question

I was messing with Area3D signals and i really wanted to know if its possible to lerp something inside a signal, would it work at all or do i need to do something else entirely?
this is very confusing to me as i am a beginner to Godot, i would appreciate if anyone could give me some tips so i could better understand how to work it out.

heres what i mean:

func _on_area_3d_body_entered(body: Node3D) -> void:
	audiofile.volume_db = 0

func _on_area_3d_body_exited(body: Node3D) -> void:
	audiofile.volume_db = -80

Is it possible to make these two lerp into eachother seamlessly? everything i tried did some weird stuff to the audio so i’ve figured i came here to ask for help.

So you want to change the volume smoothly using lerp? Here is a way:

  1. Define a variable, like var target_volume = 0
  2. set it instead of audiofile.volume_db in the area body entered/exited function
  3. add this code in the physics process:
audiofile.volume_db = lerpf(audiofile.volume_db, target_volume, delta*10.0)

If I am right, it should work.

Maybe you want to Tween the value upon entering and exiting? What’s the exact use case?

1 Like

i want to make it so when you enter the Area3D the volume of an audio goes up gradually, and when i get out of it it goes down gradually as well

Then you can also try this:

var tween = get_tree().create_tween()
tween.tween_property(audiofile, "volume_db", 80, 5)
tween.play()
await tween.finished
tween.queue_free()

But I think it is best to use the lerp for it, as I mentioned in the first post.

3 Likes

Oh wow, its this simple?! XD, Thanks dude!

1 Like

Tween will start playing and will be freed afterwards automatically, no need to specifically do that. You can also call create_tween() function on the Node itself instead of the SceneTree, it will then automatically bind it to the Node, which usually has an added benefit. You can simplify the code to just this and it will do the same:

var tween = create_tween()
tween.tween_property(audiofile, "volume_db", 80, 5)
2 Likes