0 Favourites

Lerp opacity?

  • 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?

  • try lerp(object.opacity,100,5*dt)

  • 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.

  • 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.

  • 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.

  • Object is just pseudocode I used for the object name. Feel free to use .self if you like.

  • 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?

  • 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.

  • 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. :)

  • 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.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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. :)

    I think you're confused about what dt does.

    Dt is the time since the last tick, and will stay the same as long as the frame rate is constant.

    Also you might take a look at the fade behavior.

    Also comparing the last value as a component of time isn't exactly correct, in that it only effects time because of the amount that it adds each tick, IE 5*dt would add less than 20*dt.

  • I use this in objet that need fade opacity : Self.Opacity-(100*dt) and after un wait system 0.3 and destroy object. Is cool when player kill enemy and work very prerry.

  • I use this in objet that need fade opacity : Self.Opacity-(100*dt) and after un wait system 0.3 and destroy object. Is cool when player kill enemy and work very prerry.

    And the reason for bumping a 3 year old thread with that remark is??

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)