Ping pong always returning value pass as argument

I’m trying to ping pong in my update and it only seems to return back the value I pass it, never any other value.

        protected update(): void{
            var value = 0;
            BABYLON.Scalar.PingPong(value, 1);
            console.log(value);
        }
        >0

So could I get anyone else to confirm this is not working or am I doing something wrong?
Also is it possible to update on the Playground? Or return a Delta time?

It works fine in this PG:

https://playground.babylonjs.com/#7DEYH3#1

I don’t see it Gijs the functions supposed to

The returned value will move back and forth between 0 and length

To me that means the value should lerp back and forth but the outputs still a static number.
Am I missing something?

With PingPong you give the distance the ball traveled and how far away the other wall is

(0.0, 1.0) => 0.0 = 0.0 ping and 0.0 pong = 0.0 - 0.0 = 0.0 :white_check_mark:
(0.5, 1.0) => 0.5 = 0.5 ping and 0.0 pong = 0.5 - 0.0 = 0.5 :white_check_mark:
(1.1, 1.0) => 0.9 = 1.0 ping and 0.1 pong = 1.0 - 0.1 = 0.9 :white_check_mark:
(1.6, 1.0) => 0.4 = 1.0 ping and 0.6 pong = 1.0 - 0.6 = 0.4 :white_check_mark:
(2.5, 1.0) => 0.5 = 1.5 ping and 1.0 pong = 1.5 - 1.0 = 0.5 :white_check_mark:
(6.0, 12.0) => 0.5 = 6.0 ping and 0.0 pong = 6.0 - 0.0 = 6.0 :white_check_mark:

image

i use ping pong this way
https://playground.babylonjs.com/#56TIIF

I guess I’m getting confused on the “Back and forth” part:
The returned value will move back and forth between 0 and length
Does that not mean that the value will constantly update, lets say I give it 0, and 10 should it not return:

[1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,…]

I’m trying to scale up and down Make a UI element shrink and expand on an update.

@ycw yes thank you, I can use this. And also thank you Gijs!

1 Like

The PingPong function has no memory, but you can give it some:

var pingPong = (function(){
    var i = 0;
    return function(tx, length){
        return 1 + BABYLON.Scalar.PingPong(tx + i++, length - 1);
    }
})();
1 Like

Thank you so much, I realized I was expecting it to hold my hand :wink: I shouldn’t be so lazy.

1 Like