Hello everybody!
Fede here, from italy: new to the forum and to unity as well ![]()
So…i’m currently working at a studio, where i have to experiment with Unity and his potential applications on the iPhone. I have only some actionscript background, but so far the transition to 3d went really smooth.
Yeah, so far.
The task i am trying to accomplish right now is to tilt an object (let’s say it’s an arrow), so that it always points upwards in the real world, of course using the accelerometer.
Seems like an easy task, right???
first try was:
function Update () {
var roty=iPhoneInput.acceleration.y;
transform.rotation.z=roty
}
//the real code is longer and has accelerometer input smoothed, but for simplicity's sake i cut it out ^_^
it works. Howewer, the accelerometer readings from y range from -1 to 1, where -1 is “home button down” and 1 is “home button up”. The problem is that “home button right” and “home button left” share the same reading (0), and i cannot tell wether the user is holding the iphone with the home button left or right. Therefore, the arrow will point upwards only for 180 degrees-for the next 180 it will point to the ground.
So, i understood i have to incorporate readings from PhoneInput.acceleration.x
second try is:
var up = Mathf.Atan2(iPhoneInput.acceleration.y, iPhoneInput.acceleration.x);
transform.LookAt (up);
//once again, bare bone code ^_^
Guess what? Unity error: No appropriate version of ‘UnityEngine.Transform.LookAt’ for the argument list ‘(float)’ was found.
of course, it’s because there is no transform component to look at; but i have no idea of how i could transmit the vector resulting from Mathf.Atan to a transform component. ![]()
So, i have finished my options. Anyone could please put me on the right trail?
Thanks in advance ![]()
Fede