x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What is the best way to smoothly update a float?

Hello,

I'm trying to create a function which will take as inputs: NewValue and Time. The goal of the function is to update a private float variable to NewValue, and it will smoothly update itself in Time seconds.

For example, the variable is set to 0 and I call the function with NewValue = 1 and Time = 1

So the variable will have to have the value "0.1" in 0.1 second, "0.5" in 0.5 second, and "1" in 1 second.

I wanted to use Lerp but the problem is that I can't set how long it has to update it, and the smooth is not the one I want, because the value will be 0.1, 0.6, 0.9, 0.95, 0.99, 0.999.... and I want 0.1, 0.2, 0.3..., 0.9, 1.

So I did a math function but I'm sure that's not the best way to do it:

alt text

(The first node branch is connected to Event Tick). As you can see it is very messy... Is there a way to use a Timeline or something like that to do what I want?

Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Jul 30 '14 at 01:04 PM in Blueprint Scripting

avatar image

Shelby
140 26 23 27

avatar image Jacky Jul 30 '14 at 01:07 PM

Have you tried FInterp To node?

avatar image Shelby Jul 30 '14 at 01:20 PM

Yes I already tried but actually I think I'm doing something wrong with it. Here's my code:

alt text

The problem is that the Test variable will increase but never reach 1. It will go to 0.9999...

I'm probably doing it wrong because it gives quite the same value as Lerp..

avatar image Shadowriver Jul 30 '14 at 02:13 PM

Thats normal, because Interp never reaches target value, just move value closer to target value and less distance i moves less closer, thats why you go this smooth effect out of it. You need to detect when value is 0.9999999 and correct it to 1 yourself. This function was made mainly for animation where 0.9999 values are irrelevent.

avatar image Shelby Jul 30 '14 at 02:48 PM

Okay, thanks. So there is no way but the one I posted on my question to have a linear increase, like this line: alt text

And not like this one: alt text

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Perhaps write your own function to do this?

ie Create a variable (float) named updateRate and another (float) targetValue.
Create a function SetNewTargetValue (with two inputs NewValue(float) and Time(float)). Within the function, set

targetValue = newValue

updateRate = (NewValue-Currentvalue)/Time

In the Tick event, do this: CurrentValue = min(CurrentValue+(updateRate*deltaDeconds), targetValue)

You will do the above only if (updateRate != 0 AND CurerntValue != targetValue)

I think this will give you a linear increase.

more ▼

answered Jul 31 '14 at 03:24 AM

avatar image

mindfane
3.4k 154 51 271

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question