Is there a way to control the gravity/ physics of objects by rotating the iPhone?
Control it how?
Can you describe what you want to do?
I would like to have the gravity be controlled be tilting the iphone. For example, if I’m holding the iPhone horizontally and some game objects are resting on the ground, I want to rotate the device and have the game objects react due to the change in gravity. here’s a video from a game example. During the video the game is rotated and the objects react. I’m guessing its changing the gravity thats effcting the objects right?
I found this code on the forum, is there a way to make this work with the iphone set to horizontal orientation? right now this only works properly in Vertical mode. thanks!
Physics.gravity = Vector3(iPhoneInput.acceleration.x, iPhoneInput.acceleration.y, 0);
There’s other forum posts on calibration, I believe.
Hmm, I might put my hardware stats into my signature too…
2 x Oct core Mac’s (10gb ram)
8 x 24" Benq monitors
1 x JVC Broadcast Monitor
4 x Quadcore q6600 workstations (overclocked to 3ghz) 8gb ram
32 x Quadcore (3ghz) workstations (8gb ram)
etc etc…
Nah, its too long
I’m using something like this to change gravity in the game according to tilt of the machine (top down camera, so z y are swapped):
Physics.gravity = Vector3 ( iPhoneInput.acceleration.x, iPhoneInput.acceleration.z, iPhoneInput.acceleration.y );
But the physics simulation seems to turn itself off after a while. Then tilting the device and thus changing the gravity doesn’t have any effect, until I move one of the objects again.
My guess is that the objects are going to sleep because no force is affecting them. But shouldn’t they be woken up when gravity changes? Is this a bug?
Is there a way to force the objects to stay awake? Or is there a WakeUp () command?
It’s a design decision rather than a bug, I suspect (although we’ve all used that excuse ). For most purposes, you would not expect gravity to change, and if it does then everything in the world will wake up at once, which would be a performance hitch, to put it mildly.
Another approach to this is not to change gravity, but to have your objects on a base that tilts along with the iPhone. If you make the camera a child of this tilting base, you will get a top-down view consistent with the angle of the iPhone. In this situation, physics certainly will be activated because the base’s collider is moving.
I tried that first. But after hours and hours of trying to convert the iPhone’s acceleration vector to a usable rotation, I still didn’t get what I wanted. Changing the gravity is so much simpler.
I have now “solved” the problem by making the floor object continuously move up and down in increments that are invisible to the eye. Of course this keeps all objects awake at all times, which is bad for performance. So it’s not an ideal solution.