Hello there,
I’m using the legacy animation system with some procedural elements for a 2.5D shooter. I’m calculating the player’s torso aiming rotation based on the weapon’s current forward, but i need it to not be affected by animations like firing. I figured i’d achieve this by saving the specifics on all animation states in the animation component, disable them all save for the aiming one, sample the weapon’s current forward and then revert back to the way the states were. For some reason this does not work and at the end of the frame i’m left with just the aiming animation playing.
What am i doing wrong?
var animStates:List.<AnimationState>;
function LateUpdate(){
SampleStates();
animationObject.animation["Aim"].enabled = true;
animationObject.animation["Aim"].weight = 1;
animationObject.animation.Sample();
currentForward=weapon.transform.forward;
RevertStates();
}
function SampleStates(){
for (var state : AnimationState in animationObject.animation){
animStates.Add(state);
}
for (state in animationObject.animation){
//iterate a second time just in case changing a state affects other states immediately
state.enabled=false;
state.weight=0;
}
}
function RevertStates(){
for(var state:AnimationState in animStates){
animationObject.animation[state.name].enabled=state.enabled;
animationObject.animation[state.name].weight=state.weight;
animationObject.animation[state.name].time=state.time;
}
animStates.Clear();
}