Leaning animation

okay… so i’ve tried but failed, im trying to make it so when the player holds “Q” the player leans to the left with an animation.

heres my code so far:

function Update () {
		// INPUT
		 var isLeaningL : boolean = false;
			if (Input.GetKeyDown(KeyCode.Q)){
					isLeaningL = true;
					print('leaning');
				}
			if (Input.GetKeyUp(KeyCode.Q)){
					isLeaningL = false;
					print('notleaning'); 
				}
			
		// ACTIONS	
		animation.wrapMode = WrapMode.Clamp;

		if(isLeaningL) {
		animation.CrossFade("leanL");
		}	
		if(isLeaningL == false) {
		animation.CrossFade("idle",1);	
	}
	}

this will get me as far as making the whole screen shift a tiny amount in about one frame (as if both animations are being played at the same time?)

im just look for a bit of code that will: on Q down play the animation leanL and then hold the last frame in the animation, then on Q up return to idle…
any help or direction would be most appreciated :slight_smile:

Hey dude,

Input.GeyKeyDown will only happen momentarily (as the key is pressed down), check your console and you’ll see print(‘leaning’); only happens once.
Try using just Input.GetKey, that will recognise holding the key down.

Pete.

ohhhh! cheers!!!

i always thought that, that meant for as long as a key is down its true, and yehh. well thats nice to know,
thank you very much :slight_smile:

Actually so did I 'till recently :slight_smile:

Hey, also it might be better to put the wrap mode stuff in the start function so it only gets called once,

function Start(){
	animation["leanL"].wrapMode = WrapMode.ClampForever;
}

Or even better, in the import settings for your object. (look down the bottom of this image)

http://unity3d.com/support/documentation/Manual/Character-Animation.html