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 Landetls · Jun 15, 2015 at 12:04 AM · forceinterpolationsmoothingcurves

Adaptive Force smoothing? (Updated)

Hey, my first question here. updated: i didnt get any answers to my first explanation so im simplifying it in hopes to get some feedback.

roughly what im trying to do:

alt text

my visual testing code(re-written since last time, and runs in the unity editor), now im using an animationcurve instead of a smoothing function:

 public class SimForce : MonoBehaviour {
 
 
     public float forcePool = 100f;
     public float maxDeltaForce = 10f;
     float forceRef = 0f;
 
     float timeRef = 0f;
     float peakForce;
     public float normalTime = 4f;
     float startTime;
     float currentTime;
     public AnimationCurve aCurve;
     public Transform tPeak;
     public Transform tTotal;
 
 
     void Start () 
     {
         TrailRenderer tr;
         tr = tTotal.gameObject.AddComponent<TrailRenderer>();
         tr.startWidth = 0.1f;
         tr.endWidth = 0.1f;
         tr.time = 100f;
         tr.material = tTotal.renderer.material;
         //tr.material.color = new Color32(100,100,100);
         tr = tPeak.gameObject.AddComponent<TrailRenderer>();
         tr.startWidth = 0.1f;
         tr.endWidth = 0.1f;
         tr.time = 100f;
         tr.material = tPeak.renderer.material;
     }
     
     // Update is called once per frame
     void FixedUpdate () 
     {
 
         if (Sim()) Destroy();
         //transform.position = mathf.lerp();
     }
 
     void Destroy()
     {
 
         DestroyObject(this);
     }
 
     bool Sim()
     {
         float force;
 
         if (timeRef == 0f) timeRef = Time.fixedTime;
         currentTime = Time.fixedTime - timeRef;
 
         //this is working!!, but peak curve isnt smoothed
         force = (forcePool) * aCurve.Evaluate(currentTime / normalTime) - forceRef;
 
         //use two stacked smoothing functions?, not effective
         //force = (forcePool) * aCurve.Evaluate(Mathf.SmoothStep(0,1, currentTime / normalTime)) - forceRef;
 
 
         //save highest peak
         if(force > peakForce) peakForce = force;
 
         var total = forceRef / forcePool * 5;
         var peak = force / (forcePool / normalTime) * 50;
 
         var x = 5 * (currentTime / normalTime);
         tPeak.position = new Vector3(x,peak,0);
         tTotal.position = new Vector3(x,total,0);
         forceRef += force;
 
         Debug.Log("force this frame = " + force + "forceoutput = " + (int)forceRef + " of " + forcePool + " currenttime = " + currentTime);
         
         if(forceRef >= forcePool) 
         {
             Debug.Log("Result = " + (int)forceRef + "/" + forcePool + " highest force experienced=  " + peakForce +" time to complete = " + currentTime);
             return true;
         }
 
         return false;
     }
 }

alt text

the peak(blue)curve amplitude is exaggerated so its easier to see. it is almost working now, i could probably get away with this smoothing function but if it could be able to do 2 more things i will have achieved my goals for it, 1: smooth the start and ending of the peak curve by a small bit, 2: clamp and smooth the highest point of the peak to the variable maxDeltaForce.

to make it clear im not asking for someone to write the code for me, im just asking for some pointers as to how to do it. this is for a free project so i wont be making any money on it. thanks:-)

unityss.png (5.4 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

2 People are following this question.

avatar image avatar image

Related Questions

Networked position interpolation implementation (not Dead Reckoning)? 1 Answer

How to fix odd interpolation issues in Unity 3 Answers

Smoothing noises with different amplitudes (Part 2) 0 Answers

Linear interpolation crash 0 Answers

How to implement Mob movement / death ? 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