Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

compass

Discussion in 'Scripting' started by ganixx, Sep 11, 2015.

  1. ganixx

    ganixx

    Joined:
    Feb 2, 2015
    Posts:
    29
    hi to all the nice peopple

    i need help to make a compass using quaternion and rotate thee compass only on the y axis.

    tks
     
  2. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    Create an empty gameObject and put it north of your map then create a compass script.

    Something like this should get you going :

    Code (CSharp):
    1. public Transform north;
    2. public Transform compassPointer;
    3.  
    4. void Update () {
    5.  
    6. Vector3 targetPos = north.position - compassPointer.position;
    7.  
    8. targetPos.y = 0;
    9.  
    10. Quaternion targetRot = Quaternion.LookRotation(targetPos);
    11.  
    12. compassPointer.rotation = Quaternion.Slerp(compassPointer.rotation,targetRot,Time.deltaTime * 2.0f);
    13. }
     
  3. ganixx

    ganixx

    Joined:
    Feb 2, 2015
    Posts:
    29
    ok tks, i will test it and then i´ll tell you how it worked.
    sorry to answer late