0 votes
asked in General Help by

Hi, i've recently been trying to create animations by making a few keyframes and interpolating between them with a curve.

For example, i've created a 2 keyframe run animation, copied and mirrored them in order to obtain 5 keyframes (first 2 are the normal animation, then mirrored, then one last frame for the loop), then i've added a script to interpolate through the animation by using an animation curve:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimatorMin : MonoBehaviour
{
    public Animator animator;
    public float speed = 1;
    public string varName = "Blend";
    public AnimationCurve curve;

    private string animName = "Locomotion";
    private float animVar = 0;

    void Start()
    {
        if (animator == null)
        {
            animator = GetComponent<Animator>();
            if (animator == null)
                Debug.Log("err: animator is null");
        }
    }
   
    public void Animate(string parameter)
    {
        animVar = (animVar + speed * Time.deltaTime) % 1;
        float point = 0;
        point = curve.Evaluate(animVar);
       
        animator.Play(animName, 0, point);
        animator.SetFloat(parameter, point);
    }

    void Update()
    {
        Animate(varName);
    }
}

However, the issue with this solution is that i can't take advantage of unity mecanim, since i have to manually handle all transitions between animations.

Currently i'm using the free version of UMotion, where i can edit curves for each and every property, but i don't see any option to edit multiple ones at a time.

I was wondering if there is a way to setup a single curve that dictates how quickly the animation plays out, as that'd allow for very quick animation prototyping (a fully rigged character only needed 2 keyframes for a decent running animation), while having all the individual curves fine-tune the movement afterwards.

Thank you in advance. :)

1 Answer

0 votes
answered by Expert (111k points)
 
Best answer
Hi Ivan,
thank you very much for your support request.

I'm not 100% sure if I understood your question correctly, but you can edit multiple curves by selecting multiple animated properties at the same time in the Clip Editor (hold [STRG] or [SHIFT] for multi selection).

If you want to change the animation speed, the easiest way would be to switch into the Dopesheet and select all keys. Then use the blue handles of the rect tool that just appeared to scale the animation.

If you want to add custom curves to your animations that will animate an Animator Parameter, check out the "Custom Property Constraint" in "Animator Parameter" mode (see "Pose Editor/Constraint System/Custom Property" in the manual).

Please let me know if you have any further questions.

Best regards,
Peter
commented by

I did check out custom property constraints and while they're quite useful, i'm afraid they aren't what i'm looking for right now.

I'll try to explain what i'm trying to do with an example:

Let's say i'm creating an animation which currently only has 2 keyframes, i'd want to be able to change how i transition between the first keyframe and the second. If i had only one property, then in the editor i'd only see one curve.

However, once i'm animating multiple propeties, i'll see something like this:

Where i have multiple curves instead of one.

If i select multiple nodes at once and try to edit them, i'll instead only edit one of them:

Or in other words, i'd like to map a single curve to all propeties at once.

The script i shared above interpolates between an animation using a curve, where value 0 represents the start of the animation and value 1 represents the end of the animation.

The advantage is being able to quickly create unrefined animations for prototyping purposes and, once refined, it's then possible to create new variations only by changing the keyframes.

Unfortunately, having to change how quickly an animation is played through a script makes it much harder to take full advantage of unity's mecanim state machine.

Being able to change how tangents are calculated for multiple propeties at once does help, but it's not the ideal solution.

An "already done" example of what i'm trying to accomplish can be seen in overgrowth, where characters are animated using just a handful of keyframes with different types of interpolation. The developers made a GDC video session that can be found on youtube and i was trying to mimic the same approach. :)

commented by Expert (111k points)

Ah OK, I understand what you mean now.

Currently you can change the length of the animation using the rect tool, but as you've already mentioned it's not possible to manipulate the tangents of multiple keys at the same time.

Due to the specific use case I currently don't plan to extend UMotion's functionality to support that. I hope you can appreciate.

Anyway I think that in your case the cleanest solution would be that you use the Playable API to extend Mecanim and define a new animation type that just has two poses and a curve that defines how to blend between them. That would allow you to live tune the curve during play mode. It's probably also closer to what the developer of Overgrowth did.

Plesae let me know if you have any further questions.

Best regards,
Peter

Soxware Support

Here you get official product support by the developer and the community for all Soxware Products for Unity®.

Post as guest, login via Facebook or create an account.

Ask questions, report bugs or provide feedback. Please use the correct category and always post in english.

For private email support, please use the Support Form to create a support ticket.

Copyright © 2017 Soxware Interactive | All Rights Reserved | Impressum

...