- Home /
Question by
unity_iXvkV2pjAX9k8A · Jul 16, 2019 at 08:01 AM ·
androidcompass
Compass.trueHeading instead of pointing at north points at the current direction my android device is pointing
I made a UI compass for android in which I want the north needle to point at north direction all the time but it points at the direction my android device is pointing at.For Example if my android device is pointing at west, the needle will point at west. I am using Compass.TrueHeading, according to unity docs it should point at geographical north. Any help will be appreciated.
This is the script I am using --
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Compass : MonoBehaviour
{
//target is the Compass needle
public Transform target;
private float north;
private void Start()
{
Input.compass.enabled = true;
Input.location.Start();
}
void Update()
{
north = -Input.compass.trueHeading;
CompassRotate();
}
public void CompassRotate()
{
target.rotation = Quaternion.Slerp(target.rotation, Quaternion.Euler(0, 0, north), Time.deltaTime * 2);
}
Comment