how to pong a Mathf.Lerp ?

No the same use that my previous post, but how to pong a Mathf.Lerp ?

is it even possible ?

Thank’s a lot for the help.

BooBi

Why do people always ask this!? :smiley:

Yes, of course it’s possible. They’re just numbers, and you can do anything you want with them (subject to the limits of the representation of course, but that has little to no bearing here).

So by ‘pong’ I assume you mean bounce back and forth. An easy way to do that is to use a wave evaluation function. A triangle wave will give you constant speed (in parametric space), while (for example) a sine function or ease-in-ease-out function will cause the interpolation parameter to slow at each boundary, reverse direction, and then speed up again.

If you need help with the math, perhaps you could describe what type of behavior you want, e.g. smooth, constant speed, etc. (If you need an example, I can post a wave function or two for you.)

[Edit: You could probably also use iTween or the built-in animation system for this.]

I want to do a blinking sphere, like a light on boats, so on and off slowly (constant) and I want to use the opacity of a transparent material to do that.

And in fact It finally rejoins my previous post which ask how to lerp some number during 2 secondes when I press play on a button.

In this case, it’s the opacity which goes from 1 to 0 (to 1 to 0,…) during 1 sec for exple.

So I had in mind to do something like that : (in general I need to type my problem in the forum and the idea comes :smile: )

Limit1 = 0
Limit2 = 1

opacity = Mathf.Lerp (Limit1, Limit2, ?time?);

and use a

if opacity = Limit2
Limit 1 = 1
Limit2 = 0
if opacity = Limit1
Limit 2 = 1
Limit1 = 0

Do you have a better idea ?

I really have difficulties with the time in Unity. I know how to use the waitforseconds etc, but when I can only use Time I’m quite often stuck.

Lol
I should maybe try that too

Mathf.PingPong

That’s not the first time I’ve explained how to do something that’s already in the Unity API - oops :slight_smile:

(I’ve never used Mathf.PingPong() myself, so it didn’t come to mind.)

I’m trying it… (the function)

But, do you know how can I do to do a Lerp during 2 sec at any time in the game ?

var StartTime=5.0;
function Update () {
if(Time.time >= StartTime){
var opacity = Mathf.PingPong(Time.time - StartTime, 1); // starts at zero at start time and fades in and out
var opacity = Mathf.PingPong(1-(Time.time - StartTime), 1); // starts at one at start time and fades in and out

}
}

My question is linked to my previous post Here

I need to start the lerp when I pressed a button then “distance = mathf.Lerp (Lim1, Lim2, time);” and I need that the lerp is during exactly two seconds whenever I’m pressed the button.

Look there for my answer…