Blending Three Animations Without Mecanim

Hello, I’m having trouble basically with making a “blend tree” of 3 animations but without using Mecanim (This is simple because my character rig is being difficult).

So long story short I’m avoiding having to re-rig my character and redoing my animations, which is why I’m unable to simply use Mecanim (Legacy animations).

  • Up : 80 x axis
  • Centre : 0 x axis
  • Down : -80 x axis

Two animations work using their weights, these being up and down. The object moves up and down (sharply) but obviously won’t centre. I’m at a loss and struggling with the centre weight thus why I’m asking for help.

Here’s the code, I know it’s terrible:

void ApplyAimRotation() {
	Camera myCamera = this.GetComponentInChildren<Camera>();
	float angle = myCamera.transform.rotation.eulerAngles.x;
	
	if ( myCamera.transform.rotation.eulerAngles.x >= -80 && 
		 myCamera.transform.rotation.eulerAngles.x < 280 ) {
		// Object Down.
		animation.Blend( "Up", -angle );
		animation.Blend( "Centre", 0 ); // No idea what to set weight as.
		animation.Blend( "Down", angle );
	}
	else if ( myCamera.transform.rotation.eulerAngles.x >= 280 && 
		  myCamera.transform.rotation.eulerAngles.x < 360 ) {
		// Object Up.
		animation.Blend( "Up", angle );
		animation.Blend( "Centre", 0 ); // No idea what to set weight as.
		animation.Blend( "Down", -angle );
	}
	else {
		// Object Centre.
		animation.Blend( "Up", 0 ); // No idea what to set weight as.
		animation.Blend( "Centre", 0 ); // No idea what to set weight as.
		animation.Blend( "Down", 0 ); // No idea what to set weight as.
	}
}

Any help is appreciated.

OK, so after spending a whole night thinking about the logic and small patterns of a Blend Tree for 3 conditions, I managed to come up with this code:

The camera has a range of -80 to +80 but works awkwardly, in that +80 is down and +270 is up. Making the code comprised of simple range based statements.

private float up = 0;
private float down = 0;
private float centre = 0;

void ApplyAimRotation() {
	Camera myCamera = this.GetComponentInChildren<Camera>();
	float angle = myCamera.transform.localEulerAngles.x;
	
	//Looking Down
	if ( angle > 0 && angle < 90 ) {
		up = 0;
		if ( angle < 45 && angle > 0 ) {	
			centre = angle;
		}
		else if ( angle > 45 ) {
			if ( centre > 0 )
				centre -= 45 - (angle - 45);
			else
				centre = 0;
		}
		down = angle;
	}
	
	//Looking Up
	else if ( angle < 360 && angle > 90 ) {
		up = angle;
		if ( angle > 315 && angle < 360 ) {			
			centre = angle;
		}
		else if ( angle < 315 ) {
			if ( centre < 360 && centre != 0 )
				centre += (315 - angle);
			else
				centre = 0;
		}
		down = 0;
	}
	
	animation.Blend( "Up", up );
	animation.Blend( "Centre", centre);
	animation.Blend( "Down", down );
}

Now this code is unfortunately slow in terms of response (there is a delay before the animation actually moves to the correct blend position) and not entirely accurate around the centre position.