Now that Unity 3.4 has support for the iPhone 4 gyroscope it makes a fantastic virtual camera controller.
Took a bit of work to sort out the various orientation issues, & so I thought I'd save anyone else the trouble.
Example package attached. Enjoy!
[updated so that it works even if camera already has a parent ie character controller etc]
Last edited by phoberman; 08-08-2011 at 01:03 PM. Reason: update
I was wondering if the user acceleration can be used to determine movement of the device itself in 3d space, rather then simply "moving" the camera...
Great gyro attitude sample! tnx
userAcceleration works in mistery mode... always Y+ and shaking. and after movement for example forward, returns back..
i dont understend how it works! ((
As far as I could determine so far the userAcceleration is a pure acceleration vector3. For some reason when you "stop" it moves "backwards", the acceleration get's less to a point where it goes to 0.
I have a question: is there a way to start the camera facing always compass north?
@JanHelleman: I've played with the accelerometer, and it seems to be useless for translation; I think it's mostly good for getting tilt and shake. Wish it were otherwise.
@bhaal: When you fire up the gyroscope, it starts out facing whatever direction the phone is facing. You'd need to read the compass to figure out which way is north (I think Prime31 has a plugin) and then you'd need to use a parent transform to compensate for whatever direction the phone is facing on startup.
Glad it's been useful - I updated the package a little so that it uses only one script (now takes care of creating the necessary parent transform)
Thanks a lot. It's so wonderful when you want to do something and it's just been done for you!
I was looking for very short distance movement of the device itself. After searching a lot I realized this gyro is A not precise enough for it and B there's to much error in the calculations according to some guy from google... To bad
phoberman. This script is the bomb. Thanks for figuring this out man.
phoberman that is a very handy script! I like it .
This script should be in the official unity wiki scripts section!!!!
Has anyone tried to use that script with a Caracter Controller?
This is a great script, thanks for sharing!
One thing I've noticed is that when I rotate the phone around the Y axis (i.e. spinning the phone flat on a table), the image does not rotate as fast as the phone. For instance, when I rotate the phone 360 degrees, the image has only rotated about 270 degrees. The other axes seem to work great. Has anyone else noticed this? Any idea what's up?
One additional detail that I've determined is that when I rotate the phone 90 in reality, it only registers as 70 degrees.
Thank you for this! Its great!
iguana_02 - Manchester United Kingdom
Thanks for sharing phoberman.
Your gyroscope is working perfectly.
Thank you so much for sharing! Great work!!!