1
\$\begingroup\$

I would like to animate a weapon being swung in 2 frames - all I'm doing is changing the position and rotation of the weapon sprite. However, I don't want unity to interpolate the rotation (generate sub-frame rotations that smooth out the animation).

How can I do this? Using flat curves (constant tangents) does not work, and my options seem to be Euler interpolation and Quaternion interpolation (there is no "No interpolation" option).

I would like to not have to make spritesheets for every frame of every weapon.

Edit: Here is my current solution, which isn't ideal since I have to specify the number of frames and the speed I want per weapon

IEnumerator AnimateAttackManually () {
    float numFrames = attackFrames-1; // 1 frame per second, zero indexed
    for(int currentFrame = 0; currentFrame <= numFrames; currentFrame++){
        animator.Play("Attack", -1, (currentFrame/numFrames));
        animator.speed = 0;
        yield return new WaitForSeconds(1/attackSpeed); 
    }
    animator.Play("Idle");
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Transform.Rotate doesn't meet your needs? Does that interpolate the rotation? \$\endgroup\$ – Cooper Jul 6 '14 at 18:04
  • \$\begingroup\$ As far as I know Transform.Rotate should indeed meet those needs (not interpolate) \$\endgroup\$ – Dries Jul 6 '14 at 18:48
  • \$\begingroup\$ So instead of adding a keyframe with the new rotation, I should add an event that calls Transform.Rotate? It doesn't look like the parameter constraints (float, string, int, object reference or an AnimationEvent object) would allow me to do that... \$\endgroup\$ – Rohit Garg Jul 6 '14 at 19:05
  • \$\begingroup\$ Do you absolutely have to use the animator for it? This is trivial to do in code alone. \$\endgroup\$ – ssb Jul 6 '14 at 23:55
  • 1
    \$\begingroup\$ Sure it's trivial in code, but the animation system should be able to provide support for this. He needs to see if there's a way to configure it to do just that. \$\endgroup\$ – leetNightshade Jul 6 '14 at 23:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.