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 EZ64cool · Nov 03, 2013 at 09:22 PM · not workingmathfmathf.clamp

Clamp not working. (solved)

So I have set up a clamp to stop my throttle from going over or under an amount. This works fine but if I hold down my accelerate button the value will go over the amount but not by much, I don't mind this much but its when I brake and my speed goes into the minuses and I start to reverse that I get annoyed. I don't know how to fix this and didn't see anyone else with this problem so help would be really nice.

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 aldonaletto · Nov 03, 2013 at 09:36 PM 3
Share

Post your script! How do you expect to get any help without showing your code?

avatar image Freaking-Pingo · Nov 03, 2013 at 10:52 PM 0
Share

$$anonymous$$y best guess would be it you are still adding to the variable's value even though it exceeds the maximum clamp value. But as @agoaldonaletto stated. Post your script.

avatar image EZ64cool · Nov 04, 2013 at 05:54 PM 1
Share

Here is my code.

 #pragma strict
 
 private var Throttle : int = 0;
 
 function Update () {
 
     Throttle = $$anonymous$$athf.Clamp(Throttle,0,$$anonymous$$axThrottle);
     
     Throttle +=Input.GetAxis("Throttle");
 
 if(Input.GetAxis("Brake") > 0)
     {
         Throttle-=(Throttle/10+1);
     }

 transform.Translate(Vector3.forward*Time.deltaTime*(Throttle/10));

}

1 Reply

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

Answer by Freaking-Pingo · Nov 04, 2013 at 07:41 PM

Switch the order of the lines:

 Throttle = Mathf.Clamp(Throttle,0,MaxThrottle);
 Throttle +=Input.GetAxis("Throttle");

to

 Throttle +=Input.GetAxis("Throttle");
 Throttle = Mathf.Clamp(Throttle,0,MaxThrottle);
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 EZ64cool · Nov 04, 2013 at 09:37 PM 0
Share

Thanks that fixed my problem. :)

avatar image Freaking-Pingo · Nov 04, 2013 at 10:11 PM 0
Share

If it resolved your problem, remember to mark my reply as the answer :).

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

17 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

Related Questions

My player shakes when Mathf.Clamp stops it from going off screen. 1 Answer

Another Mathf.Clamp Not Working on Rotate? 1 Answer

Mathf.Clamp() or your own Clamp fn, which is better? 1 Answer

Make my player who uses Character Controller to stop moving in one certain direction once it reaches the borders. 1 Answer

Limit camera pan not working 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