how to make mathf.pingpong not from 0
hello everyone. it might be stupid question but how we can modify the range of mathf.pingpong? i already trying from another question but it just keep fails. so how to make the ping pong not start from 0 ? thanks
Answer by UnityCoach · Jan 06, 2017 at 01:17 PM
 Mathf.Lerp (min, max, Mathf.Pingpong(Time.time, 1));
 
              @UnityCoach thanks for the answer. i have tried it but it gave me an error. it says 'UnityEngine.Vector3' does not contain a constructor that takes 1 arguments' this is the code i use
  transform.position = new Vector3($$anonymous$$athf.Lerp(-3, 3, $$anonymous$$athf.PingPong(Time.time , 1)));
 
                  is it wrong?
This will return a float value going between -3 and 3 over time. Now, if you want to assign it to a position, you need to "build" a Vector3, what you're doing with Vector3 (x, y, z);
So, if you want the Y position to pingpong :
 transform.position = new Vector3(0, $$anonymous$$athf.Lerp(-3, 3, $$anonymous$$athf.PingPong(Time.time , 1)), 0);
 
                  thank you so much @UnituCoach it worked perfectly
Answer by YaoZhang · Apr 30, 2019 at 03:18 PM
to change its range, you can do something like this
 //suppose you are changing its value on X-axis
 //oscillate from a to b, but never get to a and b.
 transform.position = new Vector3(mathf.PingPong(Time.time, b) + a, transform.position.y,transform.position.z)
 
              Answer by Zeerox_ · Jul 25, 2019 at 12:20 PM
Just in case someone want to know. PingPong in x axis.
 > float minimum,maximum;
 > 
 > void Update() {
 >     transform.position = new Vector3(Mathf.PingPong( Time.time ,
 > maximum-minimum) +minimum,
 > transform.position.y,
 > transform.position.z); }
 
              Answer by anurag03062001 · Apr 21 at 09:54 AM
Use mathf.sin instead . Do something like Mathf.sin(time.deltatime/speed)+ length; You can modify your length ie if ist 4 , it will go from -4 to 4.
Your answer