- Home /
Clamping negative and positive values.
Hi, I'm rather new to Unity. Though I'm familiar with JavaScript's environment but not the best. Now what I'm trying to do is clamp the origin, for example, if X=0 and over time X increments by 1, if X>=10, X then starts to descend into negatives X -= 1 rinse-and-repeat for negative x hitting 10.
However, from past occurrences on other game engines, (using C++) I would just perform a Clamp(); to the value of X. Here's my code at the moment.
transform.localPosition += Vector3(0 , 5 * Mathf.Sin( Time.deltaTime ) ,0);
Answer by Jessy · Jun 21, 2011 at 02:46 PM
http://unity3d.com/support/documentation/ScriptReference/Mathf.html
Mathf.PingPong(Time.deltaTime, 20) - 10
You shouldn't post a comment as an answer, ins$$anonymous$$d, leave a comment on the answer.
Your answer
Follow this Question
Related Questions
Mathf.Lerp Question 2 Answers
Finding the Current Vector of Travel 1 Answer
how to use time on lerp 2 Answers
How to make Y-Axis face away from a position? 2 Answers
Make value change to anoter over time and back loop 3 Answers