How would I blend these animations?
Hey, I've been searching around the forums to help maybe wrap my head around this, but I can't seem to get this to work. I'm trying to allow my character to "shoot" (play a recoil animation) while walking (walking animation). I can't cross fade the recoil animation because it won't play all the way through, and I tried Animation.Blend but it didn't seem to work. If anyone could help me out that would be great. Also, the recoil animation in held in a child object of the object holding the walking animation, if that helps any.
if (walkingState == WalkingState.Running && !IsAiming && walkingState != WalkingState.Idle && VelocityMagnitude > 5.5f)
{
WalkAnimationHolder.animation["M1911Run"].speed = VelocityMagnitude / RunSpeed;
WalkAnimationHolder.animation.CrossFade("M1911Run", 0.5f);
CameraAnimationHolder.animation["Camera Run 1"].speed = VelocityMagnitude / RunSpeed;
CameraAnimationHolder.animation.CrossFade("Camera Run 1", 0.5f);
}
else if (walkingState == WalkingState.Walking && VelocityMagnitude < 5.5f || VelocityMagnitude > 3.5f)
{
WalkAnimationHolder.animation["M1911Walk"].speed = VelocityMagnitude / WalkSpeed;
WalkAnimationHolder.animation.Blend("M1911Walk",0.5f);
CameraAnimationHolder.animation["Camera Walk 1"].speed = VelocityMagnitude / WalkSpeed;
CameraAnimationHolder.animation.Blend("Camera Walk 1", 0.5f);
}
else
{
WalkAnimationHolder.animation.CrossFade("M1911Idle",0.2f);
CameraAnimationHolder.animation.CrossFade("Camera Idle 1", 0.5f);
}
if (Input.GetButtonDown ("Fire1")) {
if(CurrentWeapon.name == "M1911")
if (walkingState != WalkingState.Running) {
if (shootime <= 0 && !RecoilHolder.animation.isPlaying) {
CurrentRotation = Quaternion.Slerp (CurrentRotation, CurrentWeapon.Recoil, Time.deltaTime);
CamRotation = Quaternion.Slerp (CamRotation, NextCamRotation, 2 * Time.deltaTime);
CurrentPosition = Vector3.Lerp (CurrentPosition, CurrentWeapon.RecoilKick, Time.deltaTime);
RecoilHolder.animation.Play("M1911Recoil");
//CamRotation = CamRotation * new Quaternion(-1, 0, 0, 0);
shootime = 1;
}
shootime -= Time.deltaTime * CurrentWeapon.firerate;
//CurrentRotation = Quaternion.Slerp(CurrentRotation, NextRotation, 0.35f);
//CurrentPosition = Vector3.Lerp(CurrentPosition, NextPosition, 0.15f);
}
Your answer
Follow this Question
Related Questions
How can i blend two(or more) animations like a blend tree, but only with scripts? 1 Answer
Play Animation on Click c# Unity 5.2 0 Answers
how to use a Mocap FBX of a full skeletal rig to animate fps hands? 0 Answers
Very low FPS because of AudioManager 1 Answer
Can I change the animation fps in Unity?,Can we change the fps of an animation from Maya? 1 Answer