- Home /
Scale using accelerometer with limits
I'm trying to translate the roll(y) of a phone into the scale of an object but with size limits.
I have had success scaling to infinity +- with the following code:
void Update () {
float accelY = Input.acceleration.y;
transform.localScale += new Vector3(0, accelY, 0);
}
The problem I am having is with the max and min limits of the scale.
I attempted to use Clamp in the following way but have ended up just limiting the direction of scale where -y (rolling toward myself) equals 0 therefore no shrinking happens and +y (rolling away from self) scales up endlessly assumed at a max rate of 0.045f.
transform.localScale += new Vector3(0, Mathf.Clamp(accelY, 0f, 0.045f), 0);
In an ideal world I'd like to have a min scale of y = 1 and a max scale y = 100 and as you roll the phone back and forth it would tween between the two sizes.
I can find code snippets for Translate and rotate but nothing for scaling.. Please help.
Your answer
Follow this Question
Related Questions
Scale using accelerometer with limits 0 Answers
The floating point origin and AI 1 Answer
VR Scale/Move 0 Answers
How can i translate my object? 1 Answer