Compass

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
(Removing all content from page)
Line 1: Line 1:
==Compass==
 
The compass script allows you to get 0-360 degree heading with respect to an arbitrary North reference object named "GPS Reference" of which the Z axis is pointed North. The compass uses a [[Sender]] to send the heading over a network.
 
  
==Code==
 
<javascript>
 
var updateFreq = 1.0;
 
private var heading = 0.0;
 
private var gpsRef : Transform;
 
private var gpsRefN : int;
 
private var sender : Sender;
 
private var timer = 0.0;
 
 
function Start(){
 
Init();
 
}
 
function Update () {
 
timer+=Time.deltaTime;
 
heading = transform.rotation.eulerAngles.y - gpsRefN;
 
if(heading<0)heading+=360;
 
if(timer>(1/updateFreq)){
 
sender.Send(heading);
 
timer=0;
 
}
 
// Debug.Log(transform.rotation.eulerAngles.y + " - " + gpsRefN + " = " + heading);
 
}
 
 
function OnEnable(){
 
Init();
 
}
 
 
function Init(){
 
var gpsRefGO = GameObject.Find("GPS Reference");
 
if(gpsRefGO!=null){
 
gpsRef = gpsRefGO.transform;
 
gpsRefN = gpsRef.rotation.eulerAngles.y;
 
sender = gameObject.GetComponent("Sender");
 
}
 
}
 
 
 
</javascript>
 

Revision as of 18:18, 19 October 2009

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox