#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Need math help - tilt calibration

Posts: 4,047Member, Sous Chef
edited 12:38AM
I know how to calibrate the tilt to a custom angle when using accelerate based on the accelerometer data, but I am using constrains not accelerate so I need some help.

Here's what I have:

constrain self.positionX to self.Position.X -( game.Accelerometer.Y *14)
constrain self.positionY to self.Position.Y +( game.Accelerometer.X *14)

The controls feel EXACTLY like tilt to live so I do not want to that to change. But currently it only works if you are holding the iPad completely level. I was hoping to have a real attribute called "calibrateY" and have the player hold the device at the desired angle tap a button and it changes game.calibrateY to game.accelerometerX.

BUT...

I can't figure out what to do with the game.calibrateY attribute. How do I work it into the equations above to allow a custom tilt?

Thanks!

• Posts: 4,047Member, Sous Chef
any math geeks out there?

• Posts: 524Member
I'm not good at math but I did a Google search and came up with this:

3D Tilt calibration

Is this what you are after? Honestly, the math is so beyond me that I'm not even sure that there's an answer in there
• Posts: 4,047Member, Sous Chef
way over my head! thanks though
• Posts: 10,376Member, Sous Chef
I probably don't understand what your asking but I made this custom calibration tutorial back in december to allow you to set a custom angle of play. maybe it'll help?
• Posts: 40Member
I believe that the problem that both scitunes and myself are having is that the gravity or simulated gravity is constrained to the value of the accelerometer. This works just fine and you can even calibrate it, but the problem comes in if you want to say calibrate it with the iphone/pod/pad in a vertical position rather than horizontal like on a table is that the calibration gets off because once of how the accelometer works.

When the device is lying flat on a table, the x and y accel. values are 0. Once put it vertical, the x or the y is 1 (depending on which side is up). Now comes the hard part. If you tilt the device 10 degrees forward the accel. value goes from 1 to .9. If you tilt the device backwards 10 degrees, the accel. value is still .9. So creating an offset to calibrate it the way that my mind works, simple doesn't work.

I'd love to see if anyone has any ideas, but I'm fresh out.
• Posts: 4,047Member, Sous Chef
@jon - you bring up a good point, but that is not my exact issue.

@mulcahy - I have used you demo before and it works great as a calibration method for the movement rules you use. The problem is that your method requires the use of an accelerate or move behavior - which I have found to be impossible to get to feel right. If you use the constrain method I describe above, the feel is almost exactly that of tilt to live. So I really want to stick with that method, I just don't know how to modify it so it works at an angle other than completely flat.

I would be happy if someone could direct me to giving the player the option of flat or 60 degrees. Obviously giving the player the ability to completely customize the angle is ideal.

Thanks!
• Posts: 10,376Member, Sous Chef
Ahh ok, i didn't think it was that easy
• Posts: 4,047Member, Sous Chef
I am hoping codemonkey or FMG will have an idea. Until then I will see if a math teacher I work with can help.
• Posts: 3,206Member
Hopefully CodeMonkey, ORBZ, or rebump will chime in and be able to help you.

I haven't worked with the accelerometers at all yet...plus I'm not really that good at math! (I'm better at logic)
• Posts: 4,047Member, Sous Chef
Thanks, Joe.

I know you say you're not good at math, but what is math if not logic?
• Posts: 3,206Member
Maybe I'm not that good at logic after all... :0)
• Posts: 4,047Member, Sous Chef
I was actually suggesting the exact opposite!

• Posts: 4,047Member, Sous Chef
Got it

You just need to add the calibrate value. For example if you want 45 degrees that is an X value of -.5 so you add .5 to the x value so that 45 degrees acts like the new zero.

so constrain self.positionY to self.Position.Y +( game.Accelerometer.X *14) becomes:

constrain self.positionY to self.Position.Y +( (game.Accelerometer.X+.5) *14) to play at a 45 degree angle.

NEW PROBLEM:

It screws up my vector to angle to get my actor to always point forward. I tried changing game.Accelerometer.X to (game.Accelerometer.X+.5) within the VectorToAngle.

Now Joe, I know you know a thing or two about vector to angle
• Posts: 4,047Member, Sous Chef
weird. The "New PRoBLEM" I described above was only a problem on my iTouch, but works perfectly on my iPad. So for now problem solved.
This discussion has been closed.