playMaker

Author Topic: Calibrate Tilt?  (Read 7819 times)

derkoi

  • Full Member
  • ***
  • Posts: 187
Calibrate Tilt?
« on: July 11, 2012, 06:04:28 AM »
Hi,

I'm using Playmakers "Get Device Acceleration" to control the player with the device tilt, however the neutral position is when the device is flat and is not very comfortable to play.

I'd like to calibrate the tilt based on the position the device is at when the level loads, I've done this before in code however I can't figure it out in Playmaker.  ???

Can someone please help?  :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #1 on: July 11, 2012, 06:30:11 AM »
Hi,

 can you provide the code sample you have, I'll see what I can do to match your routine.

bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #2 on: July 11, 2012, 06:51:48 AM »
Sure.

I've chopped out some other irrelevant parts of the script.

Code: [Select]
using UnityEngine;
using System.Collections;

public class playerControlScript : MonoBehaviour {

public Vector3 restPosition = new Vector3(0,0,-1);
Quaternion calibrationRotation;


void  Calibrate (){
        Vector3 acceleratorSnapshot = Input.acceleration;
        calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition);
    }

void Start (){

Calibrate();

}

void Update() {

CalculatePitchAndRoll();

}

void CalculatePitchAndRoll() {

Vector3 accelerator = Input.acceleration;
                Vector3 Calibaccelerator = calibrationRotation * accelerator;

pitch = Calibaccelerator.x;
roll = -Calibaccelerator.y;

}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #3 on: July 11, 2012, 07:47:42 AM »
hi,

 ok, and then what do you do with "calibrationRotation" during the game loop?

 bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #4 on: July 11, 2012, 07:53:10 AM »
calibrationRotation stores the date from the calibration i think

Code: [Select]
calibrationRotation = Quaternion.FromToRotation(acceleratorSnapshot, restPosition);
And then it gets multiplied by the accelerator input?

Code: [Select]
Vector3 Calibaccelerator = calibrationRotation * accelerator;

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #5 on: July 13, 2012, 05:04:01 AM »
Did you manage to get it working jeanfabre?  :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #6 on: July 13, 2012, 08:24:43 AM »
Hi,

 ok, I created the necessary custom actions needed for you to achieve what you want.

 https://hutonggames.fogbugz.com/default.asp?W967

It's pretty self explanatory, however, if you have trouble understanding how it works let me know

bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #7 on: July 13, 2012, 08:33:05 AM »
Thanks! I appreciate it.  :)

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #8 on: July 14, 2012, 04:33:11 AM »
Jean, I can't find the download links for the actions you posted? I've no doubt missed something.  :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #9 on: July 16, 2012, 03:01:49 AM »
Hi,

 my mistake, forgot to add the attachement! :) so go to that quaternion page again and you will be able to download the package with the all them custom actions.

https://hutonggames.fogbugz.com/default.asp?W967

 bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #10 on: July 16, 2012, 05:37:22 AM »
Thanks Jean,

I've set it up and it works to some extent but there's a lot of 'noise' in the final output. See attachment image.

How can I get the float values to just use the first 3 digits??

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #11 on: July 16, 2012, 06:32:56 AM »
Hi,

 Have you tried the high pass filter?

https://hutonggames.fogbugz.com/default.asp?W592

Bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #12 on: July 16, 2012, 06:35:17 AM »
Yeah, it doesn't seem to make much difference. I need to filter the output Floats for X,Y,Z rather than the Vector3 before it.

I tried converting each float to an int and then back to floats, that worked but I can only get values of -1, 0 or 1 which isn't very good.  :(

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Calibrate Tilt?
« Reply #13 on: July 16, 2012, 06:42:53 AM »
Hi,

 then, you might actually want to use the device roll actions instead.

https://hutonggames.fogbugz.com/default.asp?W575

bye,

 Jean

derkoi

  • Full Member
  • ***
  • Posts: 187
Re: Calibrate Tilt?
« Reply #14 on: July 16, 2012, 06:45:20 AM »
How can I make that work for a rolling ball that I need to tilt forward,backwards and left,right? I thought it only rotated around the Z axis?