Question about Lerping?

Godot Version

4.2.2

Question

Hi all,

I have set up some code in my HUD to modulate a group of objects out of the HUD using a fade-out with the modulate_a keyword. Now it works, the thing is once the process is running I can’t find a way to stop it.

This is the process function:

func _process(_delta):
	#only called when all gems are gotten
	if(blue_gem_bool && red_gem_bool && green_gem_bool):
		#so far so good -one to start with other to follow
		# Need to set start, end speed vars 
		await modulate();
		
		#t.tween_property(gem_text, "modulate/a", 0, 5)
	blue_gem_bool = false;
	#pass

this is the modulate function:

#modulate the group out of view - fade

func modulate():
	# Need to set start, end speed vars 
	#blue.self_modulate.a = lerp(start,end,speed)
	var i = blue.self_modulate.a;
	print ("i: "+str(i) );
	var x: float = 0;
	
	blue.self_modulate.a = lerp(i, x, .1);
	gem_text.self_modulate.a = lerp(i, x, .1);
	green.self_modulate.a = lerp(i, x, .1);
	red.self_modulate.a = lerp(i, x, .1);
	
	return;

So, it is running but is is continually running. The bool values that start the loop are never set to back to false, and if I do at any point set them to false the lerp will stop running - like I have in my code in the process.

So, how to I setup the code so that the bool variable go back to false at some point and stop the loop continually calling the modulate() function. I tried using await as a method but that didn’t work I was going to try returning a signal but I have no idea how that really works.

So, any and all help is greatly appreciated in this matter.

Regards.

Could you check if all gems are collected only when a gem has been collected? (Rather than every frame)

Using a tween once is a much better idea than using lerp. Second best would be using move_toward instead of lerp.

Your modulate function awaits nothing, there isn’t anything time-related about it. lerp is a math function that has the following definition:

func lerp(a, b, t):
    return a + (b - a) * t

Probably, but, that won’t solve the current problem of using the lerp, I was trying to make it quick and easy, to get it working.

Believe me if I knew enough to use tween and move_toward I would. The tutorial that I was using as the base for this game barely touched on those subjects, let alone how and what they are. I couldn’t give you a definition for a tween. Lerp I have used before in Unreal and Unity to open doors,draw bridges and stuff, but I can’t remember how the code around the lerp was structured. It was a long time ago

Well, at least I know that now :stuck_out_tongue:

Well, if you have a “collect gem” style function, or anywhere you set x_gen_bool to true, try your tween again, it is very close to correct

var t: Tween = gem_text.create_tween()
t.tween_property(gem_text, "modulate:a", 0.0, 5.0)

Looking at your other posts I highly recommend the animation player as well, very powerful tool in Godot.

It too late to try that now but I get on it as soon as I can, well, … later in the morning.

And that code wasn’t from me that was from another gentleman in an almost concurrent question.

I am going to need to make a series on game development - How to Make a Game - one problem at a time :rofl:.

Cheers mate.

I realized that if the tween was going to work, I could move the checking code for the gems out of the process, which is what you were saying. Anyway, I was having problems with the Tweening code it kept saying that the file had no tweeners in it, when it obviously did and what’s why why I originally ditched the idea. I was about to post the error message when all of a sudden the Gem Text slowly faded before my eyes!!! I was about the post the “error” message, I swear computers hate me.

So, I just wanted to say thankyou again for persevering with me because it’s now working. All I need to do is make the other things fade as well and that part is finished.

Regards.