- Home /
Which transform properties can be set in a scripted animation?
The documentation of AnimationClip.SetCurve describes that common property names that can be used for scripting animations are: localPosition, localRotation and localScale.
But the transform class also has properties for transformations in world space like position, rotation and eulerAngles or in local space like localEulerAngles.
Is it possible to modify these as well? I tried, but animations on this properties get ignored. When I try to check them in the animation window I get the message, that I should clean up left over properties cause they can not be found in the object. So I guess it is not possible. Is there any documentation on this?
Answer by Blazor Ramone · Mar 09, 2012 at 02:24 AM
I'm not 100% sure, but I think the way things work in Unity as well as some other 3d engines is that objects (transforms) are only really responsible for the local components of their transforms and that the other values, such as world space position and rotation and things like Euler angles, are calculated from or translated to local coordinates when needed. One clue to this is the fact that in the inspector, particularly in Debug mode, you will only see the localPosition, localRotation, and localScale are shown. So it would seem that animation curves will only directly let you manipulate these local values, but there maybe some things you can do to achieve similar effects to manipulating the other values. For instance if you add animation curves to a transform that has no parent( the root game object not necessarily the root node in a skelton) its local position rotation etc will be equivalent to a worldspace coordinate. Concievably if you happen to know the position of all the parent transforms you can figure out the local position to set in order to get a desired world coordinate I think it would be something like
//psuedo code
desiredlocalPos = desiredWorldPos - Sum(all parents localPositions * rotation)
I'm not sure that the normal TransformPoint / InverseTransformPoint or WorldToLocal/LocalToWorld matrixes will work in these contexts as the transforms may not be set when creating an animCurve. Also the only way you could really know all the parent positions is if you also set the keys on all of them for the same frame. This seems like it would get dangerous...
Euler angles are another property Unity has to calculate as it really uses Quaternions to represent orientation. Luckily there is a static function Quaternion.Euler that you can use convert Euler to Quaternion so if you wanted to set local eulers to the animation curve you could do something like:
Quaternion desiredRot = Quaterion.Euler(x,y,z);
clip.SetCurve("", Transform, "localRotation.x", curvex);
clip.SetCurve("", Transform, "localRotation.y", curvey);
clip.SetCurve("", Transform, "localRotation.z", curvez);
clip.SetCurve("", Transform, "localRotation.w", curvew);
curvex.AddKey(time, desiredRot.x);
curvey.AddKey(time, desiredRot.y);
curvez.AddKey(time, desiredRot.z);
curvew.AddKey(time, desiredRot.w);
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Add Mixing Transform Doesn't Work!! 4 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Rotating An Object On Its Axis Once 3 Answers
Unity 3d(Space) Questions 1 Answer