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 jaja1 · Dec 26, 2014 at 07:11 PM · c#guilerpjitter

GUI objects jitter when following "lerped" Gameobject [SOLVED]

I have a gameobject being lerped/slerped between two positions and quaternions by an AI script on my server. The Healthbar that follows the monster seems to jitter between random positions sometimes even going off screen and coming back.

How do I fix the jitter-like movement of GUI objects "following" a gameobject?

EDIT: A video showing what happens (a bit hard to see because my game runs at 60 fps and the recorder runsa at 32 fps) https://www.mediafire.com/?6hcuccn1787p3s8

Comment
Add comment · Show 14
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 LucasMars · Dec 26, 2014 at 08:12 PM 0
Share

Could we please have the code? People can't help, otherwise.

avatar image jaja1 · Dec 26, 2014 at 08:25 PM 0
Share

@Lucas$$anonymous$$ars ...sorry about that. Here is the code:

 void OnGUI ()
 {
 //health bar
         if(blood > 0 && this.gameObject.GetComponentInChildren<Renderer>().isVisible && disFrom$$anonymous$$ainChar() <= 12f)
         {
             if(!bloodBarG.enabled)
             {
                 bloodBarG.enabled = true;
                 bloodBarR.enabled = true;
             }
 
             float factor = (float)blood / (float)initBlood;
             bloodBarG.transform.position = Camera.main.WorldToViewportPoint(this.gameObject.transform.position);
             bloodBarG.transform.localScale = new Vector3(0.002f * factor, 0.0002f, 0);
             bloodBarR.transform.position = Camera.main.WorldToViewportPoint(this.gameObject.transform.position);
         }
         else
         {
             bloodBarG.enabled = false;
             bloodBarR.enabled = false;
         }
 
 }
avatar image LucasMars · Dec 26, 2014 at 08:29 PM 0
Share

What effect are you trying to achieve with this? A health bar?

What is the object that is "this"?

avatar image jaja1 · Dec 26, 2014 at 09:07 PM 0
Share

The GUI object I am referring to is the health bar. "this" is referring to the "monster" gameobject that the health bar follows. Here is a video of what is happening. Sorry for the poor quality but my recorder does not go above 32 fps: https://www.mediafire.com/?6hcuccn1787p3s8

avatar image LucasMars · Dec 26, 2014 at 09:12 PM 0
Share

I think I may have found the issue. First, I want to make sure it is the issue I think it is.

Comment out the line: bloodBarG.transform.localScale = new Vector3(0.002f * factor, 0.0002f, 0);

Does it still jitter? If it does, then I will see what else is wrong. If it doesn't, I know an easy way to fix it.

Show more comments

1 Reply

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

Answer by Victory Dan Greene · Jan 07, 2015 at 05:22 PM

Maybe try setting the position and scale of the health bar only once, on Update() instead of OnGUI()?

OnGUI() can be called multiple times per frame, which might explain the jitter.

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

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

28 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

why is my GUI script bugging other GUI scripts? 0 Answers

Using OnGUI to change text in 3D text object. 1 Answer

Smooth Camera transition (linear interpolation) Error 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