Recording animations

Please see the URL below. http://www015.upp.so-net.ne.jp/kira-kira/recording_sample.html

Click "Record" button, and click or drag on the screen. Then, click "stop" button.

click "play" button to see your replay.

In this sample, the position is recorded correctly, but the rotation is not. I dont know what is wrong with my code.

Help me please...

the code is like below.

function startRec() {
    posXCurve = new AnimationCurve();
    posZCurve = new AnimationCurve();
    rotXCurve = new AnimationCurve();
    rotYCurve = new AnimationCurve();
    rotZCurve = new AnimationCurve();
    rotX2Curve = new AnimationCurve();
    rotY2Curve = new AnimationCurve();
    rotZ2Curve = new AnimationCurve();
    recStart = true;
    isRecording = true;
}

function stopRec() {
    print("STOPPED!!");
    isRecording = false;
    clip1.SetCurve("", Transform, "localPosition.x", posXCurve);
    clip1.SetCurve("", Transform, "localPosition,z", posZCurve);
    clip1.SetCurve("", Transform, "localRotation,x", rotXCurve);
    clip1.SetCurve("", Transform, "localRotation,y", rotYCurve);
    clip1.SetCurve("", Transform, "localRotation,z", rotZCurve);
    clip1.SetCurve("_d_camera", Transform, "localRotation,x", rotX2Curve);
    clip1.SetCurve("_d_camera", Transform, "localRotation,y", rotY2Curve);
    clip1.SetCurve("_d_camera", Transform, "localRotation,z", rotZ2Curve);

    obj.animation.AddClip (clip1, "aniMo");

}

function playAnim() {
    obj.animation.Play("aniMo");
}

function FixedUpdate () {
    if(recStart) {
        nowTime = 0;
        recStart = false;
    }

    if(isRecording){
        posXCurve.AddKey(nowTime, mainObj.transform.localPosition.x);
        posZCurve.AddKey(nowTime, mainObj.transform.localPosition.z);
        rotXCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.x);
        rotYCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.y);
        rotZCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.z);
        rotX2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.x);
        rotY2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.y);
        rotZ2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.z);

        nowTime = nowTime + Time.deltaTime;
    }
}

The code is working for me if I change the part where it adds Keyframes in the update function.

I changed:

rotXCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.x);
rotYCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.y);
rotZCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.z);

To:

rotXCurve.AddKey(nowTime, mainObj.transform.localRotation.x);
rotYCurve.AddKey(nowTime, mainObj.transform.localRotation.y);
rotZCurve.AddKey(nowTime, mainObj.transform.localRotation.z);

mainObj is the same GameObject that is being used when you add keyframes to the position curve and it is recording the localRotation instead of the localEulerAngles.

Sorry if the formatting is a bit off and I hope this will fix you’re problem.

you are mixing up localRotation and localEulerAngles for recording and storing

and float comparison is never a good idea: Comparing Floating Point Numbers, 2012 Edition | Random ASCII – tech blog of Bruce Dawson

if(isRecording){
posXCurve.AddKey(nowTime, mainObj.transform.localPosition.x);
posZCurve.AddKey(nowTime, mainObj.transform.localPosition.z);
rotXCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.x);
rotYCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.y);
rotZCurve.AddKey(nowTime, hRotObj.transform.localEulerAngles.z);
rotX2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.x);
rotY2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.y);
rotZ2Curve.AddKey(nowTime, vRotObj.transform.localEulerAngles.z);

        nowTime = nowTime + Time.deltaTime;

}

hi… when i am trying to play ma animation an error appears saying

Key count: 1 on curve ‘_d_camera’
UnityEditor.DockArea:OnGUI()

any suggestion???

hi ,
I want to record a live motion on unity 3d . how can do this ? whts is the file format does unity 3d save a recorded file .
Thanks

clip1.SetCurve(“”, Transform, “localPosition,z”, posZCurve);
clip1.SetCurve(“”, Transform, “localRotation,x”, rotXCurve);
clip1.SetCurve(“”, Transform, “localRotation,y”, rotYCurve);
clip1.SetCurve(“”, Transform, “localRotation,z”, rotZCurve);

You Used Commas not ‘.’

I solved this myself....

Thank you.