Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sylon87 · Feb 07, 2019 at 11:21 AM · uiscript.

Move UI based on player movement

Hello guys.

I hope someone can help me.

I have my player rotate from 0 to 180, and i want to move mu UI to allow it to stay in a certain position near player head.. i thought to clamp player rotation in a range of 0-1 then move my UI from -5 to 5 based on the player position, -5 for bottom position and 5 top one... But i can’t figure out to how clamp it.. Anyone can help me?

Comment
Add comment · Show 12
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 xxmariofer · Feb 07, 2019 at 11:23 AM 0
Share

setting up your canvas render mode to world space. and updating its transform as other objects

avatar image Sylon87 · Feb 07, 2019 at 12:05 PM 0
Share

I already did it, i want to know just how to clamp player rotation into a range of 0 1

Thank’s you anyway

avatar image xxmariofer Sylon87 · Feb 07, 2019 at 12:13 PM 0
Share

clamp player rotation? you mean that when player rotation is 360 make it 1? and when is 180 0.5 for example?

avatar image Sylon87 · Feb 07, 2019 at 12:15 PM 0
Share

Yes exactly

avatar image xxmariofer Sylon87 · Feb 07, 2019 at 12:24 PM 0
Share
 float yourDesiredRotation = player.transform.rotation.eulerAngles.x / 360;

change the x for y or z if you want the other angles.

avatar image Sylon87 · Feb 07, 2019 at 12:33 PM 0
Share

Thank’s you! Sorry for my question but for a $$anonymous$$us is working in the same way?

avatar image xxmariofer Sylon87 · Feb 07, 2019 at 01:02 PM 0
Share

no, try tihs code

     float angle =  player.transform.rotation.eulerAngles.x;
     float desiredValue = 0;

     if(angle >= 0)
     {
         desiredValue = angle / 360;
     }
     else
     {
         desiredValue = (360.0f + angle) / 360;
     }
avatar image Sylon87 xxmariofer · Feb 07, 2019 at 02:37 PM 0
Share

really, really thank's you!

avatar image misher · Feb 07, 2019 at 04:45 PM 0
Share

Why don't you parent your UI to the player's head so it will automatically follow and remain on the same position relative to it.

avatar image Sylon87 misher · Feb 07, 2019 at 11:11 PM 0
Share

befause i already did it and it's not following player head as expected..

avatar image xxmariofer Sylon87 · Feb 07, 2019 at 11:20 PM 0
Share

didnt work my answer?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Sylon87 · Feb 08, 2019 at 02:28 AM

         if(_playerAngle[id] >= 0)
         {
             _target[id] = _playerAngle[id] / 360;
             float FixedY = Mathf.Lerp(12f,13f,_target[id]);
             Vector3 fixedPos = new Vector3(_iconObject[id].transform.position.x,FixedY,_iconObject[id].transform.position.z);
             _iconObject[id].transform.position = fixedPos;
         }
         else
         {
             _target[id] = (360 + _playerAngle[id]) / 360;
             float FixedY = Mathf.Lerp(12f,13f,_target[id]);
             Vector3 fixedPos = new Vector3(_iconObject[id].transform.position.x,FixedY,_iconObject[id].transform.position.z);
             _iconObject[id].transform.position = fixedPos;
         }


this is what i have

Comment
Add comment · Show 2 · 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 Sylon87 · Feb 08, 2019 at 02:37 AM 0
Share

my mistake, it was just because i has to lerp from 13 to 12 on the negative one..., well now is working fine until it go on a full 360 rotation in that case it will go out of that range...i'm missing something?

avatar image Sylon87 · Feb 08, 2019 at 03:21 AM 0
Share

the problem is on value that will return a value bigger than -180, so it will get wrong... there is a way to fix it to return a value on the -180 and 180 range?

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

171 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 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 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 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 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 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 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 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 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 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 avatar image

Related Questions

UI Positioning relative to Parents Scale 0 Answers

I need to move a sprite when an UI button is clicked 1 Answer

How to get float value based on the element size? 0 Answers

Why when using a ui button script with ui toggle to interact with another script it's not working good ? 1 Answer

a live updating button panel? pulling from an external api? 0 Answers


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