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 $$anonymous$$ · Mar 19, 2020 at 05:34 PM · mathsmoothmathfrepeatmathf.lerp

Mathf repeat at the end? help!

Hello! I need to make it when the Mathf.lerp function reaches the set value, that is, at the end, it repeats

How could I do this?

Thank you!

 ClutchTorque = Mathf.lerp (MaxClutchTorque2, MinClutchTorque, ClutchSpeed);
 

 

Comment
Add comment · Show 2
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 metalted · Mar 19, 2020 at 05:53 PM 0
Share

What are you trying to achieve? I mean repeating a linear interpolation isn't very useful. You approach the value until you reach it. Repeating the lerp isnt going to do anything because you are already at the value...Could you explain your idea a little further ?

avatar image $$anonymous$$ metalted · Mar 19, 2020 at 08:52 PM 0
Share

I have a video for reference, look when the car makes gear changes (second 0:11 of the video)

https://www.youtube.com/watch?v=TrLjq1PEhOI&list=PLpBVLiNEBD_XZehek$$anonymous$$wa76qsfK2PfjDi$$anonymous$$∈dex=2

I am trying to imitate that with $$anonymous$$atf.lerp

that is, that it reaches the target value and goes down even more in a fast way and short

1 Reply

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

Answer by metalted · Mar 19, 2020 at 09:25 PM

So after your explanation about the gears rpm, it became much clearer what your objective was. I just created this bit of code on the fly, and i cant test it at the moment. But this would be how i would start tackling the problem:

 public struct Gear{
     float minRPM;
     float maxRPM;
     
     public Gear(float _minRPM, float _maxRPM){
         minRPM = _minRPM;
         maxRPM = _maxRPM;
     }
 }
 
 public class GearShift : MonoBehaviour {
 
     private Gear[] gears = new Gear[6];
     private float currentRPM = 0;
     private int currentGear = 0;
     
     private float revUpSmoothTime = 0.3f;
     private float gearChangeSmoothTime = 0.1f;
     
     private bool rpmUP = true;
     
     
     public void Start(){
         gears[0] = new Gear(0f, 3000f);
         gears[1] = new Gear(1200f, 3200f);
         gears[2] = new Gear(1400f, 3400f);
         gears[3] = new Gear(1600f, 3600f);
         gears[4] = new Gear(1800f, 3800f);
         gears[5] = new Gear(2000f, 4000f);
     }
     
     public void Update(){
         
         if(rpmUP){
             //Move the rpm to the max rpm of the current gear.
             currentRPM = Mathf.SmoothDamp(currentRPM, gears[currentGear].maxRPM, ref rpmVelocity, revUpSmoothTime);
             
             //If we reach the max rpm of this gear:
             if(gears[currentGear].maxRPM - currentRPM < 0.01f)
             {
                 currentGear++;
                 rpmUP = false;
             }
         }
         else
         {
             //Move the rpm to the min rpm of the current gear.
             currentRPM = Mathf.SmoothDamp(currentRPM, gears[currentGear].minRPM, ref rpmVelocity, gearChangeSmoothTime);
             
             //If we reach the min rpm of this gear:
             if(currentRPM - gears[currentGear].minRPM < 0.01f)
             {
                 //Start rev up again:
                 rpmUP = true;
             }        
         }        
     }
 }

We just define the different gears and their rpms. Move up to the max rpm, change gear, move down to the min rpm when changing, go up to max rpm, change gear, repeat... The change of the rpms is a bit more complicated than this because the closer you get to the max rpm of that gear, the slower the rpms will go up so you might want to factor that in. If you just want to keep it simple for now, like this script, you definitely need 2 smoothing/lerp functions: one for rpm up and one for rpm down.

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 $$anonymous$$ · Mar 19, 2020 at 09:51 PM 0
Share

Thanks you!

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

135 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

Related Questions

Why is there no Mathf.Truncate? 2 Answers

[Math] Why is this possible ? 1 Answer

Making an enemy face the Player 0 Answers

Mathf.Lerp is just jumping to maximum, no 5.0 interpolation. 1 Answer

Casting-related error: "^ cannot be applied to double and int" 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