How to make a custom gravity according to your accelerometer
Zoyt
Member Posts: 374
Hello,
I'm woking on a type of level chooser where when you tilt the device, the levels will topple to your device gravity. The problem is, I'm a neat programmer freak and will not unlock actors from their prototype to change the scene attributes (the gravity attribute). So here's my problem:
My method of accomplishing this is to find the angle between the center of the screen and the accelerometer. Then I tell all my levels to accelerate in that direction, but I the formula doesn't seem to be working right. Here is my formula (beware, it's long):
If you could help me fix/simplify this, that would be wonderful.
Thanks a lot!
I'm woking on a type of level chooser where when you tilt the device, the levels will topple to your device gravity. The problem is, I'm a neat programmer freak and will not unlock actors from their prototype to change the scene attributes (the gravity attribute). So here's my problem:
My method of accomplishing this is to find the angle between the center of the screen and the accelerometer. Then I tell all my levels to accelerate in that direction, but I the formula doesn't seem to be working right. Here is my formula (beware, it's long):
atan((( game.Accelerometer.Y +1)/2* game.Screen.Size.Height )/ (( game.Accelerometer.X +1)/2* game.Screen.Size.Width ))-atan(( game.Screen.Size.Height /2)/( game.Screen.Size.Width /2))
If you could help me fix/simplify this, that would be wonderful.
Thanks a lot!
Best Answers
-
JohnPapiomitis Posts: 6,256First off you cant change the scene gravity attribute in game.
Make a real attribute called direction. Any actors you want to have the gravity put a accelerate behavior and have the direction attribute as its direction
then constrain direction attribute to: (vectorToAngle(game.Accelerometer.X,game.Accelerometer.Y)+90)%360 -
JohnPapiomitis Posts: 6,256
Thanks @JohnPapiomitis. I'll try that when I get to my computer. But if you unlock actors, can't you change scene attributes?
Yes but certain attributes you cant change in game.
Answers