Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 da_egg5 · Jan 14 at 01:13 AM · gameobjectvelocityuser interface

Can I get a rigidbody's velocity and convert it to a fill value of an image?

I am currently in the midst of trying to create what would essentially be the equivalent to a Vertical Speed Indicator. I have two images created separately that meet in the middle and fill in the opposite direction. And I am trying to find/create a code for example that would scale the fill image as the gameobject goes forward/backwards & up/down.

The problem I'm running in to is while I know how to set the fill image based on a certain velocity ex. 'if (playerRb.velocity.y = 5) indicatorUp.fillValue = .25;' obviously that isn't actually taking the velocity and applying it.

Comment
Add comment · Show 3
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 MakerBen · Jan 14 at 01:19 AM 0
Share

Im not sure im understanding... Do you mean ```

 indicatorUp.fillValue = mathf.clamp(playerRb.velocity.y/100,0,1)

``` That would make the indicatorUp.fillValue equal to the velocity of the player / 100 so it fits between 0 and 1 until it goes past 100/100 (or 1) and then it gets clamped to 1 for any higher values

avatar image da_egg5 MakerBen · Jan 14 at 01:58 AM 0
Share

Ok, that seems very helpful. Why did you divide it by 100 though?(edit, never$$anonymous$$d obvious why you divided it by 100 lol)

To clarify and try to be concise. Lets arbitrarily say that 20 is the max velocity for a given object. For simple math I'll say on the image that will be portraying the velocity of said object there will be four labels. So, with that in $$anonymous$$d, say the object is traveling at a velocity of 5, I would want that to set the fillvalue of indicatorUp to .25 so it will be 25% full. And obivously so on, velocity of 10 = .5... And hopefully that is clear enough.

EDIT: Also my apologies, fillAmount not fillValue.

avatar image da_egg5 MakerBen · Jan 14 at 02:20 AM 0
Share

Thank you! I took my socks off and did some public math. indicatorUp.fillAmount = Mathf.Clamp(playerRb.velocity.y / 20, 0, 1);

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mf41z · Jan 14 at 09:21 AM

You'll probably need a max velocity value. Let's say you make the velocity fill a bar ( Like a health bar in a game ). So you could do something like this

     private void Update()
     {
         Vector3 vel = GetComponent<Rigidbody>().velocity;
         Vector3 maxVel = new Vector3(10f, 10f, 10f);
         Image imageX;
         imageX.transform.localScale.x = vel.x / maxVel.x * parentImage.transform.localScale.x; 
     }

I didn't test that and that probably wont work but it's something along those lines. You set the scale of the image depending on the velocity. You add a max velocity so the bar doesn't burst out of the parent. Max vel can be dynamic, just change it to watever you like during runtime as well. Did that help you?

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 da_egg5 · Jan 15 at 08:00 AM 0
Share

Someone actually answered it in the comments using the mathf.Clamp() function. Which worked out really great but I appreciate the help. I'm not super sure I follow your code because it doesn't involve doing anything with imageX.fillValue.

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

201 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 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

rigidbody.velocity not working on x axis 2 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

How to Send a GameObject Flying in a Random Direction but With Always the Same Velocity? 1 Answer

How I can change the speed of an object with the speed of sound so they are evenly matched? 2 Answers

Cannot precisly get the Transform(position and rotation) and velocity of the HTC vive controller in Unity 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