x


How to: make changes to a var over real time units instead of frame units? Mathf.Lerp

The following changes the variable myVar each frame, but how do I change it every certain number of milliseconds? Let's say every .1 seconds.

Mathf.Lerp(myVar, 0.0f, 0.5f)

more ▼

asked Dec 29 '10 at 02:32 PM

dissidently gravatar image

dissidently
450 50 55 60

If you use Mathf.Lerp(myVar, 0.0f, 0.5f * Time.deltaTime) you will get a consistent lerp rate no matter what the frame rate.

Dec 29 '10 at 07:03 PM yoyo
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Use InvokeRepeating:

var myVar : float;

function Start () {
    InvokeRepeating("LerpVar", .1, .1);
}

function LerpVar {
    myVar = Mathf.Lerp(myVar, 0.0, someIncrement);
}
more ▼

answered Dec 29 '10 at 02:52 PM

Peter G gravatar image

Peter G
15k 16 44 136

how do I turn off the invokerepeating once it's gotten to the target desired number?

Dec 29 '10 at 03:47 PM dissidently

the other problem, aside from not being able to turn it off... it seems to launch straight to the destination value... doesn't seem to take it's time getting there at all.

Dec 29 '10 at 03:51 PM dissidently

Use CancelInvoke() to turn it off. What is your someIncrement? Try a lower value.

Dec 29 '10 at 04:46 PM Peter G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Topics:

x822
x572
x379
x92

asked: Dec 29 '10 at 02:32 PM

Seen: 1138 times

Last Updated: Dec 29 '10 at 02:32 PM