Accelerometer Compensation and Vector To Angle

SinequanonSinequanon Member Posts: 35
edited November -1 in Working with GS (Mac)
Hey,

I'm posting this because I do need some help with it but I've also seen a few people asking about how to compensate for tilting with the accelerometer. I go into detail here with how I've set up my attributes so that the actor moves with the accelerometer and how to compensate for a tilting global attribute. After that, I do have a problem I'd love to get some help with. Thanks. :)

So I've got a problem with the accelerometer and using VectorToAngle. Currently I'm using controls that can be found in the tutorial project "Silky Smooth Tilt Demo with Calibration". This uses constrain properties on the X and Y positions of my actor to move it around. It also allows a calibration mechanism that I've got set in my pause menu, so that you can set the accelerometer's compensation to a comfortable viewing angle.

The code I'm using looks like:

self.Position.X -( game.Accelerometer.Y *15)
self.Position.Y +((min(.5,max(-.5,( game.Accelerometer.X + game.calibratedAccel ))))*15)

calibratedAccel is a real value that ranges in typical use from 0.3 to 0.5.

The problem is that I also need the actor to actually face the direction it's going in. Using a constrain attribute on the position X and Y do not cause the actor's velocity to actually change. Originally, my code read:

Rotate To Angle: vectorToAngle(10* self.Motion.Linear Velocity.X ,10* self.Motion.Linear Velocity.Y ) speed: 1400

Since the velocity was 0 for X and Y, this behavior didn't work.

To solve that, I reintroduced the TShirtBooth-style accelerometer control, which uses Move behaviors in the 4 cardinal directions. I also needed to build in a compensation for the accelerometer. As an example, the move up rule looks like:

When game.Accelerometer.X > .02- game.calibratedAccel, Move Direction: 90 relative to Scene, additive at speed 10*abs( game.Accelerometer.X ).

This gave it a very small velocity (no more than velocity 10, so it doesn't conflict with my constrains meaningfully) but it also allows the Vector To Angle above to see a large enough Linear Velocity X and Y to derive an angle.

The problem is this: When game.calibratedAccel = 0, which it is before I do any calibration, the actor moves perfectly and everything's happy. When I set the calibratedAccel attribute (which again has a real value in the range of 0.3 to 0.5 typically), it causes the Vector to Angle property to screw up and causes the actor to (mostly) point downward.

What compensation can I make on the computation of Linear Velocity X and Linear Velocity Y within VectorToAngle to compensate for the calibratedAccel attribute being non-zero?

Comments

  • SinequanonSinequanon Member Posts: 35
    Hey, as an update: I solved this. The TShirtBooth stuff, using Move Direction: 90 relative to Scene additive at speed 10*abs(game.Accelerometer.X + game.calibratedAccel), same for the down direction. Hope it helps.
Sign In or Register to comment.