Can the animation be displayed with a keyframe specification?

Asked 2 years ago, Updated 2 years ago, 87 views

I am currently making TPS (Third Person Shooting) at Unity.

I would like to display the key frame I specified when I was armed, but I don't know how to do it.If you move the mouse cursor, your face will follow you.

I'm sorry it's hard to understand.
Enter a description of the image here
The Unity version is 5.

unity3d

2022-09-30 19:24

1 Answers

It is difficult to get keyframes for animations, but you can calculate them from AnimationClip's frameRate to display them in a specified frame.

public class TestAnimation:MonoBehavior
{
    private animator_animator;

    void Awake()
    {
        m_animator=GetComponent<Animator>();
    }

    public void SetAnimationFrame(inti_frame)
    {
        varclipInfoList=m_animator.GetCurrentAnimatorClipInfo(0);
        varclip=clipInfoList[0].clip;

        float time=(float)i_frame/clip.frameRate;

        varstateInfo=m_animator.GetCurrentAnimatorStateInfo(0);
        variationHash = stateInfo.shortNameHash;

        m_animator.Play(animationHash, 0, time);
    }
}

src=

However, if you want to point your face or gun in the direction of the mouse cursor, you should calculate the direction on the script and set the rotation of transform instead of animation.


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.