Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SmattyCore · Aug 25, 2013 at 06:53 PM · compassdirections

Compass directions (N, E, S, W)

Hey there,

is there a way to get the directions North, East, South and West depending where the player is looking at?

I tried it with the rotation but then noticed that it changes if the player moves, of course.

Kindest Regards, Matt

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Aug 25, 2013 at 07:16 PM 0
Share

You could put an empty gameObject at your "North" and math-ify from that? I put together this but on rereading your question I'm not sure it helps since you don't want the player's "facing" direction:

 using UnityEngine;
 using System.Collections;
 
 public class FacingDir : $$anonymous$$onoBehaviour {
 
 
     private Transform myTransform;
     private float facingDir;
     
 
     void Start () {
         myTransform = transform;
     
     }
 
     void Update () {
         
         if(Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.F)) {
             facingDir = $$anonymous$$athf.Abs(myTransform.eulerAngles.y);
             if (facingDir > 360) facingDir = facingDir % 360;
             Debug.Log ("Facing: " + facingDir + " degree");
             } 
     }
 }

The facingDir, ins$$anonymous$$d of going to debug.log, could be piped into something else that approximates a direction (i.e anything near 0 is North, near 90 is East, near 180 is South, near 270 is West, etc)

avatar image SmattyCore · Aug 25, 2013 at 07:42 PM 0
Share

The solution from robertbu worked well.

avatar image SmattyCore · Aug 26, 2013 at 02:54 PM 0
Share

Hey guys, me again. Well, as you can see the directions are working well and I tried using four GUITexts to store the N,E,S,W letters. (They change if the player looks into another direction).

But as you can see on the $$anonymous$$imap is that the GUITexts are not only rendered on the $$anonymous$$ainCamera but also on the $$anonymous$$inimap which uses an extra camera.

Do you know a good resolution?

$$anonymous$$indest Regards, $$anonymous$$att

$$anonymous$$imap

minimap.png (154.7 kB)
avatar image robertbu · Aug 26, 2013 at 02:56 PM 0
Share

You want to use Layers and the layer mask on the camera:

http://docs.unity3d.com/Documentation/Components/Layers.html

Note when asking a new questions that is technically unrelated to the original one, please open a new question. It keeps UA cleaner as a repository of information, and it likely will get you a better answer. Fewer people look at already answered/older questions.

avatar image SmattyCore · Aug 26, 2013 at 03:20 PM 0
Share

Thanks. Worked good and is very easy to use.

Okay I will keep that in $$anonymous$$d ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by robertbu · Aug 25, 2013 at 07:10 PM

Asssuming your character is on the XZ plane with positive 'Z' as north:

 #pragma strict
 
 function Update () {
     var v = transform.forward;
     v.y = 0;
     v.Normalize();
     
     if (Vector3.Angle(v, Vector3.forward) <= 45.0) {
         Debug.Log("North");
     }
     else if (Vector3.Angle(v, Vector3.right) <= 45.0) {
         Debug.Log("East");
     }
     else if (Vector3.Angle(v, Vector3.back) <= 45.0) {
         Debug.Log("South");
     }
     else {
         Debug.Log("West");
     }
 }

Depending your your use, there are other, perhaps more efficient ways.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SmattyCore · Aug 25, 2013 at 07:40 PM 0
Share

Thanks for the fast reply, it works well for me :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Use of the compass on Unity 0 Answers

Why I can not enable compass (I gave it time to warm-up)? 0 Answers

Input.compass.trueHeading sucks! 1 Answer

Horizontal scrolling style compass 3 Answers

Input.compass & Input.location for Smart-glasses(non-handheld devices) issue. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges