Dive Board



Simple Calibration Script

Simple Calibration Script

by Sephiroth on Mar 25th, 2014 23:50 PM

The drift was driving me mad so wrote a quick fix to tide us over until Stefan releases his new controller :) It turned out to be trickier than I thought. It works by rotating the player in the opposite direction and at the same rate as the drift. Kind of a hack but it works for me! ^_^

I'm using Stefan's first person controller. The script is attached to the Dive Camera, and the rotation_gamerobject needs to be set to the Player (the parent of the Dive Camera the FPSInput Controller is attached to).

How to Use
Start your game and put the phone in the Dive. Press "Calibrate". In 5 seconds calibration will start which will give you time to put the Dive down on a level (and stable) surface while it calibrates. Calibration lasts an additional 5 seconds, so 10 seconds after pressing "Calibrate" the game should stop drifting and you can play away!

I've left the drift stats on there for your own reference. Of course you can initialise the calibrate function any way you want.

Hope it works for you. :)

calibration.cs

using UnityEngine;<br />using System&#46;Collections;<br /><br />public class calibrate &#58; MonoBehaviour {<br /><br />	private Vector3 offset = new Vector3(0,0,0);<br />	private float firstVector;<br />	private float angle;<br />	public GameObject rotation_gameobject;<br />	private string buttonText = &quot;Calibration&quot;;<br /><br />	protected IEnumerator calibration() {<br />		buttonText = &quot;Calibration in 5 Seconds&quot;;<br />		yield return new WaitForSeconds(5);<br />		offset = new Vector3(0,0,0);<br />		buttonText = &quot;Calibrating&quot;;<br />		firstVector = transform&#46;eulerAngles&#46;y;<br />		yield return new WaitForSeconds(5);<br />		angle = transform&#46;eulerAngles&#46;y - firstVector;<br />		angle = ((angle) % 360)/5;<br />		offset = -new Vector3(0,angle,0);<br />		buttonText = &quot;Calibration Complete&quot;;<br />		yield return new WaitForSeconds(1);<br />		buttonText = &quot;Calibration&quot;;<br />	}<br /><br />	void Update () {<br />		rotation_gameobject&#46;transform&#46;Rotate(offset * Time&#46;deltaTime);<br />	}<br />		<br />	protected void OnGUI()<br />		{<br />				if (GUILayout&#46;Button (buttonText, GUILayout&#46;Height (80))) {<br />					StartCoroutine(calibration());<br />				}<br />				GUILayout&#46;Label(&quot;Offset&#58; &quot; + offset&#46;y + &quot; degrees per second&quot;);<br />		}<br />}<br />

Sephiroth

Posts: 45

Joined: 17.03.2014

dive-owner


Re: Simple Calibration Script

by maximee9 on Mar 26th, 2014 00:01 AM

Hahahaha this is great thank you!! :D

I had thought of the exact same fix but never got around to make it . Good job.

maximee9

Posts: 5

Joined: 02.03.2014


Re: Simple Calibration Script

by Sephiroth on Mar 26th, 2014 00:33 AM

No worries :) I'm sure Stefan's method will be far more elegant, but at least out head's won't be spinning in the meantime!

Sephiroth

Posts: 45

Joined: 17.03.2014

dive-owner


Re: Simple Calibration Script

by Stefan on Mar 30th, 2014 00:38 AM

thats pretty elegant ;)
but we are working on something similar !

Stefan

Posts: 129

Joined: 30.06.2013

dive-owner


STATISTICS


Total posts: 171536


Total topics: 41569


Total members: 44827


Newest member: Daniel G.