Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

AnimationCurve error and solution

Discussion in 'Documentation' started by Ippokratis, Mar 13, 2016.

  1. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,521
    Hi,
    I read the documentation about animation curves, here : http://docs.unity3d.com/ScriptReference/AnimationCurve-ctor.html
    When I tried to run the supplied script, I got the following error :
    It is easy to fix, by creating a new Vector3. If you use this code though and apply it on a cube, you will see the cube going up and to the right, disappearing from the screen.
    Perhaps using the WrapMode as follows could provide a more interesting example. You get a cube that goes up and down. User can modify the curve characteristics in Editor during runtime and watch how the cube motion changes.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class AnimCurveExample : MonoBehaviour
    5. {
    6.     public AnimationCurve curve ;
    7.    
    8.     void Start()
    9.     {
    10.         curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
    11.         curve.preWrapMode = WrapMode.PingPong;
    12.         curve.postWrapMode = WrapMode.PingPong;
    13.     }
    14.    
    15.     void Update()
    16.     {
    17.         transform.position = new Vector3(transform.position.x, curve.Evaluate(Time.time), transform.position.z);
    18.     }
    19. }
     
  2. duck

    duck

    Unity Technologies

    Joined:
    Oct 21, 2008
    Posts:
    358
    Thanks Ippokratis! Not only for reporting the problem, but also providing an improved replacement. We really appreciate the effort. This will be in the next online update of the docs, (this friday!)
     
    Unity-Nikos and Ippokratis like this.