I am trying to move object A (wherever it currently is) to object B’s location and orientation by creating animation curves through scripting.
The following code works exactly as expected for position, but not for rotation. Any ideas?
var targetA : GameObject;
function Start () {
var startPx = transform.localPosition.x;
var startPy = transform.localPosition.y;
var startPz = transform.localPosition.z;
var startRx = transform.localRotation.x;
var startRy = transform.localRotation.y;
var startRz = transform.localRotation.z;
var endPx = targetA.transform.localPosition.x;
var endPy = targetA.transform.localPosition.y;
var endPz = targetA.transform.localPosition.z;
var endRx = targetA.transform.localRotation.x;
var endRy = targetA.transform.localRotation.y;
var endRz = targetA.transform.localRotation.z;
var curvePx = AnimationCurve.EaseInOut(0,startPx, 3, endPx);
var curvePy = AnimationCurve.EaseInOut(0,startPy, 3, endPy);
var curvePz = AnimationCurve.EaseInOut(0,startPz, 3, endPz);
var curveRx = AnimationCurve.EaseInOut(0,startRx, 3, endRx);
var curveRy = AnimationCurve.EaseInOut(0,startRy, 3, endRy);
var curveRz = AnimationCurve.EaseInOut(0,startRz, 3, endRz);
// Create the clip with the curve
var clip = new AnimationClip();
clip.SetCurve("", Transform, "localPosition.x", curvePx);
clip.SetCurve("", Transform, "localPosition.y", curvePy);
clip.SetCurve("", Transform, "localPosition.z", curvePz);
clip.SetCurve("", Transform, "localRotation.x", curveRx);
clip.SetCurve("", Transform, "localRotation.y", curveRy);
clip.SetCurve("", Transform, "localRotation.z", curveRx);
// Add and play the clip
animation.AddClip(clip, "test");
animation.Play("test");
}
@script RequireComponent(Animation)
If I pause during runtime and tweek the rotation curve a teeny-tiny bit, the curve snaps to the expected easein/easeout. I know rotations get complicated math-wise with quaternions and eulers- do rotations need to be handled differently? I couldn’t find any examples in the help.
Thanks in advance!
(fixed typos)
