Thursday, July 14, 2022
HomeGame Developmentunity - Why is my animation leaping to the final keyframe when...

unity – Why is my animation leaping to the final keyframe when set in script?


I’m attempting to rotate a gameObject by scripting it. This gameObject is a bone added in SkinningEditor, which mustn’t make a distinction. The script I wrote under is connected to the bone.

 utilizing System.Collections;
 utilizing System.Collections.Generic;
 utilizing UnityEngine;
 
 public class DeformBone : MonoBehaviour
 {
     void LateUpdate()
     {
         setAllCurves();
     }
 
 
     personal void setAllCurves()
     {
         var angle = Quaternion.Euler(0, 0, 5);
 
         var rotXcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.x);
         var rotYcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.y);
         var rotZcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.z);
         var rotWcurve = AnimationCurve.EaseInOut(0, 0, 5, angle.w);
 
         // set the curve right here
         AnimationClip clip = new AnimationClip();
         clip.legacy = true;
 
         clip.SetCurve("", typeof(Rework), "localRotation.x", rotXcurve);
         clip.SetCurve("", typeof(Rework), "localRotation.y", rotYcurve);
         clip.SetCurve("", typeof(Rework), "localRotation.z", rotZcurve);
         clip.SetCurve("", typeof(Rework), "localRotation.w", rotWcurve);
 
         // play the curve right here
         if (gameObject.GetComponent<Animation>() == null)
         {
             // add the element
             var animation = gameObject.AddComponent<Animation>();
             animation.playAutomatically = false;
             animation.wrapMode = WrapMode.PingPong;
             
         }
 
         GetComponent<Animation>().AddClip(clip, "rotateyo");
         GetComponent<Animation>().Play("rotateyo");
     }
 }

Nevertheless, the animation jitters shortly forwards and backwards, leaping from keyframe to keyframe after which it will get quicker and quicker till it simply appears to be like a bit loopy. I need it to rotate on the angle indicated slowly. I’ve tried placing this in Begin() – this solely jumps it to the final keyframe the place it stays, and FixedUpdate/Replace the place the identical factor occurs.

I can see within the Inspector that I’ve efficiently added an Animation to the bone and that the curves are being arrange correctly. What am I doing unsuitable?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments