I’m currently working on a game that relies on gravity always being applied to the player. Gravity must always be perceived by the player as pushing downward in the real world no matter which way they rotate the device. So the game world never rotates, only the phone.
Is this doable via the iPhone/Pod/Pad? Or should I tell the boss not to buy the unity apple sdk and go for android instead?
You have full access to the accelerometer from within Unity, so it’s not a problem to switch the gravity force depending on phone orientation. Or keep it constant, if that’s what you wanted.
Ok… so I can prevent the screen from changing orientation when the phone moves and have the orientation only effect which way gravity pushes?
Basically on the pc prototype i’ve made the user rotates the level on the z and relies on gravity’s downward push to get the player through the level… in the pc prototype the user has to use the left and right arrows to rotate the level, but on the phone i just want the user to rotate their phone…
Also how accurate is the accelerometer? Does it only work in 45 or 90 degree increments or could i slowly rotate the phone and each degree of rotation can be utilized?
You can prevent the orientation from changing, yes. The accelerometer is my oppinion very accurate, it’s virtually floating point precision. Test out some of the zillion balance-type games available on the app store to get a feel for it I guess.
Be sure to average the results from the accelerometer if it is jittery 3 frames average should be fine. And tweak the update frequency in xcode. It typically updates faster than your framerate by default.
So what you’re saying is to create a buffer essentially? Like keep track of the last 3 vectors(or whatever form the data is provided) and return the average to wichever methods need the data?