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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

curve key tangent mode in runtime (or other way to make a value between two keys constant)

Discussion in 'Scripting' started by sixolar, Sep 23, 2019.

  1. sixolar

    sixolar

    Joined:
    Jan 8, 2014
    Posts:
    37
    Hi,

    I'm using a particle system with a calculated velocity over lifetime curve to make a wind effect that passes through some given waypoints. This require the particles to go in a fixed direction until they reach the next waypoint, then change to the next direction, etc.. So I used AnimationUtility.SetCurveTangentMode (or SetKeyTangentMode) with the "constant" tangent mode and that works fine in the editor, but AnimationUtility is not available in builds.

    How can I have the same result without AnimationUtility?
    I tried looking for the reference code of these functions (https://github.com/Unity-Technologi...r/Mono/Animation/AnimationUtility.bindings.cs) but those are external and I have no idea how they work... I undestand it has to do with inTangent and outTangent of the keys, however I could not find any values for those that would work.

    Thanks in advance !
     
  2. sixolar

    sixolar

    Joined:
    Jan 8, 2014
    Posts:
    37
    Okay so just in case someone find this looking for the same thing : it seems to work for me to have all keys inTangent to 0 and outTangent to float.PositiveInfinity...

    If it doesn't, try using AnimationUtility functions in the editor until it works, then log your keys inTangent and outTangent, and use those values