Accelerometer in Two Orientations
Hey guys,
The game I'm working on is designed for working on the iPhone in portrait mode and portrait upside down. However, I'm using accelerometer to control the actor's left and right movement. But there's a problem with the accelerometer:
In portrait mode the game.Accelerometer.X works fine, but in portrait upside down mode, it's backwards because the device is oriented different. So the player has to tilt right to go left and tilt left to go right
So how does should I set this up so no matter which orientation you're in, you can still tilt the iPhone left to go left and tilt right to go right?
Thanks,
Henry
P.S. My rule is accelerometer rules are:
when game.accelerometer is less than -0.01
-- constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
when game.accelerometer is more than 0.01
-- constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
The game I'm working on is designed for working on the iPhone in portrait mode and portrait upside down. However, I'm using accelerometer to control the actor's left and right movement. But there's a problem with the accelerometer:
In portrait mode the game.Accelerometer.X works fine, but in portrait upside down mode, it's backwards because the device is oriented different. So the player has to tilt right to go left and tilt left to go right
So how does should I set this up so no matter which orientation you're in, you can still tilt the iPhone left to go left and tilt right to go right?
Thanks,
Henry
P.S. My rule is accelerometer rules are:
when game.accelerometer is less than -0.01
-- constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
when game.accelerometer is more than 0.01
-- constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
Comments
Make 2set of rules, 1 for portrait, and another one for portrait upside down (which all you have to change is add a minus)
Roy
I knew the screen orientation attribute was there, but where should I put the minus?
Ok ,
You basically have 2 set of rules right..
---------------------------------------------
1) when game.Screen.Device Orientation IS Portrait :
when game.accelerometer is less than -0.01
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
when game.accelerometer is more than 0.01
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
---------------------------------------------
---------------------------------------------
2) when game.Screen.Device Orientation IS Portrait UPSIDEDOWN :
when game.accelerometer is less than 0.01 (WE DROPPED THE MINUS HERE)
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
when game.accelerometer is more than -0.01 (WE ADDED THE MINUS HERE)
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
---------------------------------------------
I think this should work for ya
Roy.
Thanks for the comment, however that didn't work... I checked the code about a million times and it still was inverted.
Thanks,
Henry
Hey , can you try this :
---------------------------------------------
2) when game.Screen.Device Orientation IS Portrait UPSIDEDOWN :
when game.accelerometer is less than -0.01 ←SEE HERE
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
when game.accelerometer is more than 0.01 ←SEE HERE
Constrain self.motion.linear velocity.x to (( game.Accelerometer.X + game.calibrate )*150)
---------------------------------------------
If this will not work either let me know and ill make you a quick template..
EDIT :
SEE THE RULES ABOVE AGAIN ,
Roy.
Roy.
Preview this onto your device , and see that it work , then look at the rules :
http://www.mediafire.com/?c1cmxom6wo7t5lb
EDIT:
I can clearly see that GS is very laggy when it comes to detect device orientation..
I made you a template to detect device orientation with the Y value of the accelerometer , i think its MUCH more accurate then using the game.Screen.Device Orientation Method , see my comment below .
Roy.
I'll have to triple check this and maybe use the Project Merger on it just to be sure. Well it's half past 4 a.m. here so I'm going to be getting some sleep now, thanks Roy!
http://www.mediafire.com/?1jy5us5fhg3279q
In this the "portrait" and the "portrait upside-down" detection is made by the Y value of the accelerometer .
This is MUCH more accurate then using the normal game.Screen.Device Orientation Method !
Hope it helps you..
Roy.
RThurman
I copied and pasted all of the rules and it still didn't work!
Do you think it has anything to do with the fact I'm using game.calibrate in my constrain attribute?
Thanks,
Henry
Glad it helps you !
@resdsky
Good morning man
Maybe its your game.calibrate fault , give me some info about what it is and what values you put in it..and ill try to figure it out .
Anyway , the template i made you should work flawlessly , so i guess something else in the code is interrupting ..
Roy.
Thanks so much for all the help! Well I have a calibrate button on my main menu and all it says is when touch is pressed change attribute game.calibrate to game.accelerometer.x and then save attribute game.accelerometer.x and it loads the attribute on the main screen. Also, I have an extra condition where it says y is > or < 0, which says game.ingum is false and I have another set of accelerometer rules for when game.ingum is true, that makes the tilt less sensitive. I don't think it could be anything besides that though, because those are the only things I changed when I copied the code!
EDIT: @JohnPapiomitis that's a good point, and I haven't been pressing calibrate.
Im terribly sorry but I'm not at home right now thats why i can help much right now (I'm from my iPhone) , its friday night after all
So if you want you can send over the project (or just a small part of it that demonstrates the issue) so i can take a look at once ill get home.
Roysadaka (at) gmail (dot) com
Roy.
Message sent
I just sent you the fixed file .
Good luck continuing your project, if you have any more questions don't hesitate to ask !
Roy.
I am running into the same problem. Would you mind posting the solution to this problem?
Thanks
I believe reading this thread and downloading the demo I made and see the 2 simple rules in it should give you the solution you seek