Lerp opacity?

Get help using Construct 2

Post » Mon Aug 06, 2012 1:51 am

Hey guys, for some reason I can't get a stupid object to lerp it's opacity.
I have a setup similar to this:

Mouse Button Down -- Set Fade to 1

Fade 1 -- MuzzleFlash Opacity = lerp(0,100,5*dt)

But it just doesn't fade at all. Anyone know what's up with it?
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Mon Aug 06, 2012 2:35 am

try lerp(object.opacity,100,5*dt)
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Aug 06, 2012 3:08 am

Ok, I expanded on what you wrote and ended up with this working(kinda):

lerp(self.opacity,self.opacity-100,5*dt)

It seems a bit 'hacky' but it works. The problem is that if your using smaller values than just 100. Like for example 10, then it'll just keep getting greater and greater. Seems so simple, and yet it wont work the way it should.

I don't know why just using integers isn't working.DoubleElite2012-08-06 03:10:56
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Mon Aug 06, 2012 3:49 am

lerp goes off of a percent from 0 to 1, so anything over 1 would be over 100 percent. lerp(0,100,0.5) would give you 50.
Also using self.opacity as the target doesn't really work here. The only thing that changes in lerp(self.opacity, 100, 5*dt) is the first argument, because the third argument is used as a percent of time, rather than a percent of the target value.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Aug 06, 2012 4:03 am

But wouldn't self.opacity and object.opacity be the same thing? They both would return the changing value, right?

I mean, using object.opacity works, I'm just not sure why.DoubleElite2012-08-06 04:03:26
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Mon Aug 06, 2012 4:25 am

Object is just pseudocode I used for the object name. Feel free to use .self if you like.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Aug 06, 2012 4:34 am

Alright, I see what you mean. Earlier I tried it, but I added the self.opacity + 100 part. Which caused issues.

So I guess my last question is, why does it work when you reference self.opacity? But not when you state an integer? Because, the second value I used is an integer, why can't the first be one as well? Why do I need to state self.opacity?
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Mon Aug 06, 2012 4:56 am

Because its getting its current opacity, which you change to a percentage of 100 every 5*dt seconds.
Basically its like saying add n amount to the total every tick, until it gets to 100.
Self.opacity is the only thing that changes.
lerp(0,100,5*dt) will always return the same value, just like lerp(0,100,0.5) will always give you 50.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Mon Aug 06, 2012 5:10 am

I always thought lerp returns a value, not changing a value. I thought it takes A and B, and uses C to pick a spot between the two. Going from 0(A) to 1(B). So if I set lerp(0,100,5*dt) to run every tick, why wouldn't it work? I', sorry if I'm not getting it. If you don't want to explain it anymore, no worries. :)
B
16
S
3
G
5
Posts: 43
Reputation: 3,880

Post » Mon Aug 06, 2012 7:44 am

You don't need lerp to gradually change the object's opacity. Just do this:

Showercover.opacity = clamp( Showercover.opacity + speed*sign*dt,0,100)

- sign is just a variable should hold a signed number 1 (1 or -1) to affect which way the opacity should change
- speed is to control how fast it fades (5 is slow-ish)
Oh, and clamp is there to make sure it stops at 0 or 100.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests