How to make a custom gravity according to your accelerometer

ZoytZoyt Member Posts: 374
edited June 2012 in Tech Support
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):
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

  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    Accepted Answer
    First 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
  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    Accepted Answer
    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

Sign In or Register to comment.