Slate Forums › Custom Clips › Animate Transform (position and rotation) Action Clip
Forgive me if this is redundant, but I couldn’t find this specific kind of clip. Basically, this just animates the position and rotation of a transform, allowing you to use the position and rotation handles to assist in recording keyframes.
There are other Transform action clips for moving and rotating objects. But they all simply set the value to a specific value per clip over the course of the clip. I missed the ability to keyframe multiple positions and rotations over the course of a clip. Granted, that can be done via the more generic “Animate Property” action clip. However, when using Animate Property for position and rotation, you don’t get position and rotation handles in the scene view. That makes Animate Property difficult to use for transforms.
This Animate Transform clip is really just a combination of the techniques used in “Look At” and “Animate Biped Limb”. The result is a clip that makes it easy to keyframe position/rotation changes to a transform:
As with the other clips I was copying from, if you leave the Blend Out value at 0, the object will remain at the final position/rotation when the clip ends. Otherwise, it will return to its initial position/rotation.
Please let me know if you find any problems with this. And on the whole, it feels like this kind of clip should just be part of Slate. Please let me know if it’s already there, and I’ve just somehow overlooked it.
The script is attached, but I’ll also paste the content below in case anyone is nervous about opening a random zip file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
public namespace SlateExtensions { [Category("Transform")] public class AnimateTransform : ActorActionClip { [SerializeField] [HideInInspector] private float _length = 1; [SerializeField] [HideInInspector] private float _blendIn = 0.2f; [SerializeField] [HideInInspector] private float _blendOut = 0.2f; public EaseType interpolation = EaseType.QuadraticInOut; private Vector3 wasPosition; private Quaternion wasRotation; public TransformRefPositionRotation targetTransform; [AnimatableParameter(link = "targetTransform")] [ShowTrajectory] [PositionHandle] public Vector3 targetPosition { get { return targetTransform.position; } set { targetTransform.position = value; } } [AnimatableParameter(link = "targetTransform")] [RotationHandle("targetPosition")] public Vector3 targetRotation { get { return targetTransform.rotation; } set { targetTransform.rotation = value; } } public override string info { get { return "Animate Trasnform"; } } public override float length { get { return _length; } set { _length = value; } } public override float blendIn { get { return _blendIn; } set { _blendIn = value; } } public override float blendOut { get { return _blendOut; } set { _blendOut = value; } } protected override void OnCreate() { targetTransform.position = ActorPositionInSpace(targetTransform.space); targetTransform.rotation = targetTransform.rotation; } protected override void OnAfterValidate() { SetParameterEnabled("targetPositionVector", targetTransform.useAnimation); } protected override void OnEnter() { wasPosition = actor.transform.position; wasRotation = actor.transform.rotation; } protected override void OnUpdate(float deltaTime) { actor.transform.position = Easing.Ease(interpolation, wasPosition, targetTransform.position, GetClipWeight(deltaTime)); var newRot = Quaternion.Euler(targetTransform.rotation); actor.transform.rotation = Easing.Ease(interpolation, wasRotation, newRot, GetClipWeight(deltaTime)); } protected override void OnReverse() { actor.transform.position = wasPosition; actor.transform.rotation = wasRotation; } //////////////////////////////////////// ///////////GUI AND EDITOR STUFF///////// //////////////////////////////////////// #if UNITY_EDITOR // protected override void OnDrawGizmosSelected() // { // var pos = TransformPosition(targetTransform.position, targetTransform.space); // Gizmos.color = new Color(1, 1, 1, GetClipWeight()); // Gizmos.DrawLine(actor.transform.position, pos); // Gizmos.color = Color.white; // } #endif } } |
Hello there,
Thank you for sharing your custom clip. There exists the Animate Properties clip, which is able to animate any property (position, rotation included), on the actor and which also shows a 3D animation curve (path) with handles.
Have you tried that by any chance?
Let me know,
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
I’m not sure if I’m missing something, or if we mean two different things when we say “handles.”
Using the built-in Animate Properties clip, I can confirm IĀ do see a 3D path when animating position. However, I don’t see a drag handle in the editor. Here’s what I see when using Animate Properties:
I see this whether I’ve turned Auto Key on or off.
Compare this to the drag and rotation handle I see when using the custom clip I’ve added, Animate Transform:
I get the position and rotation handles in the editor, even with Auto Key enabled, so I can very easily drag the cube around and have it create keyframes as I do.
Is there something I’m missing about how to get Animate Properties to show me the drag/rotation handle?
Oooh š You mean the position/rotation handles. I thought you were talking about keyframe tangent handles.
That is a good point. I will add position/rotation (possible scale as well) handles in the official Animate Properties clip. Is there any other difference?
Join us on Discord: https://discord.gg/97q2Rjh
No other difference. Animate Properties was fine with that one exception of not having position/rotation handles on the object itself. That will be a useful addition.
There was one thing I couldn’t find a way to do: Make an action clip thatĀ just showed a rotation handle. In addition to making a “Animate Transform” clip, I also thought it would be useful to create an “Animate Rotation” clip, which was only for rotations. This is useful for certain bones that only rotate but don’t translate. However, the trouble I had is that in Slate, it seems that a rotation handle requires a position handle to sync it up to. In other words, I couldn’t renderĀ just a rotation handle without also rendering a position handle. But since I was ignoring the position in my “Animate Rotation” clip, it didn’t work very well, and go out of sync.
So, I imagine it’s pretty straightforward for Animate Properties to show a position handle. But it might be tricky to show just a rotation handle when animating only rotation. Maybe that will require decoupling the rotation and position handles from each other.