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 Catlard · Aug 19, 2011 at 05:03 AM · tweeneasing

Quadratic easing motion confusion!

Howdy!

So, for fun, I thought I would attempt to hand-code some easing functions into Unity, to move some cubes around. I had a look at Penner's tweening chapter (pdf here) for help with the equations. I've been able to get the easing in working, and the easing out working, but when I try to get an object to ease in and out and reach a specified position, I'm running into various problems. I have all my code here -- if you slap the code below on a gameobject and then watch it move, the problem should be clear.

I'm attempting to code the in-out easing motion by performing two half-tweens, which take place in half the time and go half the distance of the original tween. Then, when viewed together, it looks like a single in-out tween. I just can't figure out what's wrong with my equations. Any hints or solutions as to what it might be? Have you guys attempted this before? Do you know of any better explanations that are better than Penner's and (more importantly) mine? Thanks for your help!

enum Ease_Type { Algebraic, Quadratic, Cubic, Quartic, Quintic, Sinusoidal, Exponential, Circular, Customized} enum When_To_Ease { In, Out, Both } var Easing : Ease_Type; var When_Easing : When_To_Ease;

var x_destination = 1.0000; var y_destination = 1.0000; var duration_of_movement = 1.00000; var custom_degree = 0.00;

private var time_remaining; private var time_counter; private var x_coordinate; private var y_coordinate; private var x_starting_position; private var y_starting_position; private var started = false; private var start = false; private var invoked_start = false; private var half_duration_of_movement; private var adjusted_for_both = false; private var reset_time_for_second_half = false;

function Awake () { time_remaining = duration_of_movement; x_coordinate = transform.position.x; y_coordinate = transform.position.z; x_starting_position = transform.position.x; y_starting_position = transform.position.y; time_counter = 0.000; }

function Update () { if(!invoked_start) { Invoke("Startup", 1); invoked_start = true; }

 if(start)
 {
     transform.position = Vector3(x_coordinate, y_coordinate, transform.position.z);
     time_counter += Time.deltaTime;
     if(time_counter < duration_of_movement) 
     {
         switch (Easing)
         {
             case Easing.Algebraic:
                 Linear_Ease(duration_of_movement, x_starting_position, y_starting_position, x_destination, y_destination, time_counter);
             break;
             
             case Easing.Quadratic:
                 Quadratic_Ease(2, duration_of_movement, x_starting_position, y_starting_position, x_destination, y_destination, time_counter);
             break;
         }
     }
 }

}

function Startup () { start = true; }

//provides a linear movement. function Linear_Ease (duration_of_movement, x_starting_position, y_starting_position, x_change, y_change, time_since_called) { x_coordinate = x_change (time_since_called / duration_of_movement) + x_starting_position; y_coordinate = y_change (time_since_called / duration_of_movement) + y_starting_position; }

//provides quadratic and exponentially based movement. requires one more variable than the linear ease, the easing_degree variable. function Quadratic_Ease (easing_degree, duration_of_movement, x_starting_position, y_starting_position, x_change, y_change, time_since_called) { time_since_called = time_since_called / duration_of_movement; switch(When_Easing) { case When_Easing.In: x_coordinate = x_change Mathf.Pow(time_since_called, easing_degree) + x_starting_position; y_coordinate = y_change Mathf.Pow(time_since_called, easing_degree) + y_starting_position; break;

     case When_Easing.Out:
         x_coordinate = -1 * x_change * Mathf.Pow(time_since_called, easing_degree) * (time_since_called - 2) + x_starting_position;
         y_coordinate = -1 * y_change * Mathf.Pow(time_since_called, easing_degree) * (time_since_called - 2) + y_starting_position;
     break;
     
     case When_Easing.Both:
         if(time_counter/duration_of_movement <= .5)
         {
             x_coordinate = x_change/2 * Mathf.Pow(time_since_called, easing_degree) + x_starting_position;
             y_coordinate = y_change/2 * Mathf.Pow(time_since_called, easing_degree) + y_starting_position;
         }
         if(time_counter/duration_of_movement > .5)
         {
             x_coordinate = -1 * x_change/2 * Mathf.Pow(time_since_called/2, easing_degree) * (time_since_called/2 - 2) + x_starting_position;
             y_coordinate = -1 * y_change/2 * Mathf.Pow(time_since_called/2, easing_degree) * (time_since_called/2 - 2) + y_starting_position;            
         }
     break;
 }

}

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

What is the best way to ease a rotation? (js) 1 Answer

Add Easing to Transform.Rotate 1 Answer

Apply multiple Lerps to the game value 1 Answer

iTween - Path inside other path 0 Answers

Is there in Unity something like Tween-effects? 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