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 /
  • Help Room /
avatar image
0
Question by JesseFox · Oct 13, 2016 at 04:49 AM · mathfmathf.clampmathf.lerpfloats

Min and Max value?

I've been trying to create a min and max value within a min and max value but it doesn't seem to be working for me the way i would like and I'm kinda stuck with ideas on how to achieve it.

So i have a speed of my game object and when it reaches a speed of 7 the ‘ cookedAmount ‘ will = the min2 value of 0 and when the current speed reaches 10 the ‘ cookedAmount ‘ will then = the max2 value of 3. currentSpeed = 8.5, cookedAmount = 2. currentSpeed = 9.5, cookedAmount = 2.25 so on...

I’ve tried Mathf.Lerp and Mathf.Clamp and they don’t seem to work properly.

 public bool overCooked;
 public float cookedAmount;
 public float min2 = 0;
 public float max2 = 3;
 
 
     (currentSpeed > 7 && currentSpeed < 10) 
         {
             overCooked = true;  
             cookedAmount = Mathf.Lerp (min2, max2, currentSpeed / 11.5f);
         } 

attempt two,

     public bool overCooked;
     public float cookedAmount;
     public float min2 = 0;
     public float max2 = 3;
 
     
         (currentSpeed > 7 && currentSpeed < 10) 
             {
                 overCooked = true;  
                 cookedAmount =  Mathf.Clamp  (currentSpeed * 0.25, min2, max2);
             } 


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

Answer by doublemax · Oct 13, 2016 at 07:29 AM

This should work, i think you just forgot the "if".

 if (currentSpeed > 7 && currentSpeed < 10) 
 {
   overCooked = true;  
   cookedAmount = Mathf.Lerp (min2, max2, currentSpeed / 11.5f);
 } 
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 JesseFox · Oct 21, 2016 at 03:55 AM 0
Share

i ended up figuring it out i had to calculate the amount each value had with each other divided by its $$anonymous$$ and max.

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

76 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

Related Questions

Save object position after drag? 0 Answers

Mathf.Clamp does not work at all. 1 Answer

Mathf.Lerp not working. 2 Answers

Mathf.Lerp for integers 1 Answer

Int not getting rounded data 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