KSP-RO / DeadlyReentry

Heat and force damage for KSP
Other
28 stars 11 forks source link

ModuleAnimation2Value #7

Closed Starwaster closed 10 years ago

Starwaster commented 10 years ago

There's an issue with unity animations where animation time wraps to 0 when it reaches the end of the animation. This actually applies to anything with WrapMode.Once

This means that when a part is not actively animating, MA2V always sees the time as 0. Frankly I'm surprised MA2V works at all since it's the default wrap mode. I first noticed this when trying to set up KSO25 landing gear to be exposed to reentry when open.

I'm working on a fix involving keeping track of animation time and direction but it's a little kludgy so I wanted to see if anyone had opinions/suggestions about this.

Starwaster commented 10 years ago

Ok, this is what I've got so far: This is in Update(). It tracks the animation time with two samples, lastTime and currentTime. If currentTime jumps back to 0 and we were tracking forwards then assume that the animation finished and set currentTime to 1. This effectively clamps it because the animation will have to start reversing in order to set isDirectionForward off. This probably should have threshold of some sort to check for insane jumps to 0.

                currentTime = anims[0][animationName].normalizedTime;

                if (currentTime == 0f && isDirectionForward)
                {
                    // Unity animation issue hax
                    currentTime = 1f;
                }

Also, at the tail end of Update()

        if (lastTime < currentTime)
        {
            isDirectionForward = true;
        }
        else if (lastTime > currentTime)
        {
            isDirectionForward = false;
        }
        lastTime = currentTime;

This is still inadequate because there's no way to tell from looking at the animation of a newly launched ship with a part in a 'retracted' state that it is retracted instead of deployed.

Starwaster commented 10 years ago

Bah! I'm chasing a Unity bug and instead it's starting to look like a Firespitter bug. (the unity bug is real, but it might not even be at work here and I think the FSwheel module is triggering the very bug it's trying to prevent) :( Can probably close this