Forum rules - please read before posting.

trigger animations with text tokens

edited December 2019 in Technical Q&A

Hello!

I am not quite sure if this question has been come up here before. I searched the forum and found similar questions about how to use tokens but no anwer to solve my problem.

I want to use five talk animations for all of my 3d humanoid characters in my game. (The animation-controller is shared with all other characters)

anim_talk_aggressive --> 1
anim_talk_normal -->2
anim_talk_sad -->3
anim_headshake_yes -->4
anim_headshake_no --> 5

I would like to use these animations as text-tokens for a more convenient and creative-flow-friendly way of telling a story since my models don't support lip-sync which is well explained in your video and handbook.

Some of these animations are very long (up to 20 seconds) in order to make a longer text look more realistic instead of looping every few seconds. Sometimes I need two or more different anim_talk animations in one line of text.

The functionality I have in mind should roughly look like this example.

[anim:2]
Hey Peter! We should talk.
[anim:stop] (after anim:stop the characters animation should go back to locomotion idle)
[wait:3]
[anim:3]
Tell me. Is it true? Have you been involved in all of this?
[anim:stop]
[wait:3]
[anim:1]
Why don't u tell me the truth?
[anim:stop]
[anim:5]

In this example the _end-token means the animation should blend back to locomotion idle. If there is no _end-token set the animation continues or blends into another anim_talk if I start one: for instance:

[anim:1]
Why on earth haven't you told us?
[anim:3]
U know we love you!
[anim:stop].

I am aware that I need to set-up the animations correctly inside the animation-controller first but I don't think that I need to use the already integrated talk-book when implementing this solution. Am I right?

My approach would involve custom events and text event tokens.

Thank you very much for any help!!

Comments

  • In this example the _end-token means the animation should blend back to locomotion idle.

    I'm not seeing any "end" token in your example, but this should indeed all be possible using speech event tokens. I would, though, take a moment to speak up for AC's Timeline integration as you can much more easily sync animations with speech.

    Speech event tokens work by hooking into the OnSpeechToken custom event - see the Manual's "Speech event tokens" chapter for details.

    Your implementation would be something like:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class TokenEventTest : MonoBehaviour
    {
    
        private void OnEnable ()
        {
            KickStarter.dialog.SpeechEventTokenKeys = new string[1] { "anim" };
            EventManager.OnSpeechToken += OnSpeechToken;
        }
    
        private void OnDisable ()
        {
            EventManager.OnSpeechToken -= OnSpeechToken;
        }
    
        private void OnSpeechToken (AC.Char speakingCharacter, int lineID, string tokenKey, string tokenValue)
        {
            if (speakingCharacter == null) return;
    
            if (tokenKey == "anim")
            {
                Animator _animator = speakingCharacter.GetAnimator ();
    
                switch (tokenValue)
                {
                    case "stop":
                        _animator.SetInteger ("CustomTalkAnim", 0);
    
                    case "1":
                        _animator.SetInteger ("CustomTalkAnim", 1);
    
                    case "2":
                        _animator.SetInteger ("CustomTalkAnim", 2);
    
                    case "3":
                        _animator.SetInteger ("CustomTalkAnim", 3);
    
                    case "4":
                        _animator.SetInteger ("CustomTalkAnim", 4);
    
                    case "5":
                        _animator.SetInteger ("CustomTalkAnim", 5);
                }
            }
        }
    
    }
    

    This works by changing an integer parameter's value (named "CustomTalkAnim") to 0,1,2,3,4 or 5 depending on the token's value - instead of playing an animation by name. This is just a suggestion, though.

    I don't think that I need to use the already integrated talk-book when implementing this solution.

    It'll depend on how your Animator Controller is set up to transition to the animations. It's not necessary on the AC side of things.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.