- Home /
Question by
CallToAdventure · Jun 28, 2012 at 09:46 AM ·
accelerometerinput.acceleration
Accelerometer angle limit
I am trying to fake a nice reflection on ipad by simply rotating an object with the reflection texture. The problem I have is with limiting the angle. I don't want the reflection to go beyond the 180 degrees limit (the upper half of a circle) because it would go in the shaded part of the object hence rendering it unrealistic.
Here's what I use now:
function Update () {
var iphonez = Input.acceleration.y;
transform.Rotate(Vector3.forward*iphonez*0.5);
}
As I tilt the ipad left and right the object will rotate nicely. But if I keep it tilted on one side the object will keep rotate the full 360 degrees and more.
Comment
Answer by hirenkacha · Jun 29, 2012 at 10:17 AM
var yMinLimit = -180;
var yMaxLimit = 180;
private var y = 0.0;
function Start()
{
//var angles = transform.eulerAngles;
//y = angles.x;
}
function Update () {
var tiltSides = Input.acceleration.y;
tiltSides = Mathf.Clamp(tiltSides, yMinLimit, yMaxLimit);
transform.Rotate(Vector3.forward * tiltSides * 1.5);
}
It's still going all the way around 360 degrees. I suppose that's as much scripting I can learn, math was never my thing :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073417im_/https://answers.unity.com/themes/thub/images/avi.jpg)