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
0
Question by pigi5 · Jan 20, 2011 at 03:03 AM · rotationcharactercontrollerongui

rotating minimap compass according to character direction

How would I script in Javascript to rotate a GUITexture using the OnGUI function according to which direction my character is facing? I have a North, south, east, west compass that I am trying to rotate on a minimap to show which direction the character is facing.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cjmarsh · Jan 20, 2011 at 04:19 AM

Something like this should do the trick: var playerDirection : Vector2 = ( 0, 1 ); var playerTransform : Transform; var deltaRotation : float = 0; var pivotPoint : Vector2; //pivotPoint is the center of your compass texture

function OnGUI() { deltaRotation = Vector2.Angle( playerDirection, Vector2( playerTransform.forward.x, playerTransform.forward.z ) ); GUIUtility.RotateAroundPivot( deltaRotation, pivotPoint ); playerDirection = Vector2( playerTransform.forward.x, playerTransform.forward.z ); //Plus whatever other code you need for the custom control }

It's not perfect as is, but with a little adaptation it should work for you.
Comment
Add comment · Show 5 · 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 pigi5 · Jan 20, 2011 at 04:47 AM 0
Share

when I set the vector2 variables at the beginning, it gives me three errors that lead me to believe that it thinks there should be no comma, and therefore, not have two numbers in the vector2 variable). Why is this?

avatar image pigi5 · Jan 20, 2011 at 04:53 AM 0
Share

It gives me these errors:

Assets/Scripts/$$anonymous$$apOpen.js(11,35): BCE0044: expecting ), found ','. (Filename: Assets/Scripts/$$anonymous$$apOpen.js Line: 11)

Assets/Scripts/$$anonymous$$apOpen.js(11,36): UCE0001: ';' expected. Insert a semicolon at the end. (Filename: Assets/Scripts/$$anonymous$$apOpen.js Line: 11)

Assets/Scripts/$$anonymous$$apOpen.js(11,37): BCE0044: expecting EOF, found '1'. (Filename: Assets/Scripts/$$anonymous$$apOpen.js Line: 11)

avatar image pigi5 · Jan 21, 2011 at 10:44 PM 0
Share

ok, i got it. apparently, you don't define vector2 variables like that, ins$$anonymous$$d you use "var playerDirection = Vector2 (0, 1)"

avatar image pigi5 · Jan 21, 2011 at 10:46 PM 0
Share

I now get this error after I start the game : The referenced script on this Behaviour is missing!

(Filename: ....\Runtime\$$anonymous$$ono\$$anonymous$$onoBehaviour.cpp Line: 1624)

avatar image pigi5 · Jan 22, 2011 at 04:53 PM 0
Share

I had some objects that were not in use, I deleted them, but I am using a different script. Thanks anyway.

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

No one has followed this question yet.

Related Questions

After adding script for rotation to look up down, look left right stopped working,After writing code for the rotation for looking up down, looking right left stopped 0 Answers

Make 3D Player look exactly at mouse with ScreenToWorldPoint? (maths Question) 2 Answers

Camera Orbit Character Rotation 1 Answer

Cant get my character to rotate properly 0 Answers

How to rotate a character controller by exactly 90 degrees with one key 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