- Home /
pingpong ----- -
I have the following :
float x = Mathf.PingPong(Time.time, 3);
float y = gameObject.transform.position.y;
float z = gameObject.transform.position.z;
gameObject.transform.position = new Vector3(x, y, z);
It moves the gameObject back and forth However Mathf.PingPong(Time.time, 3) put the gameObject at some other place in the scene.
How can i fix that?
Your question title does not clearly describe your question.
Your question of "put the gameObject at some other place in the scene" is too vague. Some other place relative to what? Please try to be clear or nobody will know what you are asking.
Answer by Ipsquiggle · Dec 13, 2010 at 10:41 PM
The trick is to specify a point that you want the object to pingpong around, something like this:
Vector3 centerPoint = new Vector3( 10, 10, 10 );
float xOffset = Mathf.PingPong(Time.time, 3); gameObject.transform.position = centerPoint + new Vector3(xOffset, 0, 0);
Of course, then any script that is supposed to modify the objects position would need to modify centerPoint
instead of transform.position
.
Your answer
Follow this Question
Related Questions
Clamping negative and positive values. 1 Answer
tangents from angle gives weird results 1 Answer
float precision, again 0 Answers
How to find inverse cos 1 Answer