Accelerometer Control Question
Agent Argyle
Member, PRO Posts: 188
@ericzingeler provided this demo for smooth accelerometer control:
I've got this method working pretty well in my game Airlift which is free for iOS if you want to have a look. But, someone recently pointed out that if you tilt the device too far up then you go down instead of up. I noticed this happens in the demo as well.
I assume this happens because the orientation flips, But it happens even if you lock the orientation of the screen by only checking landscape right when publishing. I tried unchecking all of the auto-rotates in the scene attributes but that didn't have any effect.
Perhaps it has something to do with the Z axis instead? Anyone have any ideas? I would love to fix this in my game.
Thanks!
Comments
I imagine it does. My game Atom smash uses the X and Y of the accelerometer to control the actor movement. I don't have those issues. I built it using a different method. If all you want is left and right.
Landscape orientation
rule when attribute device accelerometer x >0.5 move up
a rule when attribute device acceleormeter x < -0.5 move down
a rule when attribute device accelerotmeter y is > 0.5 move left
and a rule when attribute device acceleormetr y < -0.5 move right
If you want the speed to go with the amount of tilt just multiply the y or x by a value like 400
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@Lost_Oasis_Games thanks for answering his question...and mine not asked yet as I am just in the beginning stages of a game using acceleration.
I'd ask also should this multiplier be done in stages according to the amount of tilt?
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
No need becuase as you tilt the number goes up so by using multiply you get a natural uptick in acceleration. What I recommend is putting a display text with the x value on a scene and run it in the viewer and you can see how the numbers move. Just make sure you lock the orientation on the device itself as the viewer does not respect the scene orientation checks.
Maybe I'll do a video on it.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Thanks @Lost_Oasis_Games - I might have to just refactor it using your method.
In the meantime, I made the speed a bit faster and this helps because by the time the player has tilted the device too far, the actor is already at the top of the screen.