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

Animation keyframe control

Discussion in 'Scripting' started by basementApe, Nov 7, 2014.

  1. basementApe

    basementApe

    Joined:
    Oct 2, 2013
    Posts:
    19
    Hi everybody,

    I'm thinking about getting into Unity again and have a question about 3D animation. I come from a 2D game logic mindset and what I want to use Unity for is a game with 2D platforming mechanics but using animated 3D meshes. I want to re-create a 2D pixel-art aesthetic with low-poly models and hand-pixelled textures and as part of that aesthetic I want to try ditching frame interpolation altogether and render keyframe by keyframe with animation speed/frame iteration controlled entirely by script. I sniffed around the scripting docs a bit but couldn't really find the kind of commandset needed to make something like that happen. But I'm probably just missing something. So is it possible to do in Unity? Can I set an animation sequence to jump instantly to a specific point within an animation clip from script? And without any interpolation?
     
  2. slay_mithos

    slay_mithos

    Joined:
    Nov 5, 2014
    Posts:
    130
    I have no clue how to do this in Unity, but I'm pretty sure on how to do it in Blender (and potentially in any other similar 3D modelling softwares).
    Note that it potentially could work in Unity too, but I never did animation directly with Unity.

    All you have to do is to have two key frames for each of your frames.
    The first one right when it should occur, the second one in the frame right before the next movement.

    You can then disable the smoothing functions, if that somehow caused issues.
     
  3. basementApe

    basementApe

    Joined:
    Oct 2, 2013
    Posts:
    19
    You mean two identical keyframes in sequence? Cool, I can try that :) I also need to be able to reference where in a clip the animation is currently at tho. Something like this pseudo-code:

    If (Character.animationFrame >= 2 && Character.animationFrame < 3) // can only grab ledge within this frame
    {
    Local_GrabLedge_Success = Check_Collision(Ledge);
    etc...
    }
     
  4. Cpt Chuckles

    Cpt Chuckles

    Joined:
    Dec 31, 2012
    Posts:
    86
    for the record i've really never touched animation in unity yet because i'm a noob
    but you can set animation events in an animation clip; maybe you could just go into those frames in the animation editor and create animation events to flip on/off boolean values that determine things like whether you can grab a ledge, etc.