My player’s arms snap into place when the aim key is pressed. How can I use lerp to increase or decrease the upperbody’s weight so his upper body doesnt just snap into position but happens more gradually?
void Actions()
{
if (Input.GetKeyDown(KeyCode.F))
{
aim = !aim;
if (aim == true)
{
anim.SetLayerWeight(1, 1);
aimik.solver.SetIKPositionWeight(1);
}
else
{
anim.SetLayerWeight(1,0);
aimik.solver.SetIKPositionWeight(0);
}
}
@Hedonsoft
I know this thread is a few months old
but, all that needs to be done is to call the 2 functions to so that you can swap between them.
Also, this is applying to layer 1 of the animator. The indexes start from 0 and go up so basically im lerping from the base layer to the next layer.
These links will help you better understand what is going on.
using UnityEngine;
using System.Collections;
public class SetLayerWeight : MonoBehaviour {
public Animator animator;
public float smoothTime;
private float yVelocity = 0.0F;
private float currWeight;
public void Update()
{
currWeight = animator.GetLayerWeight(1);
}
public void UnarmedActive ()
{
float startWeight = Mathf.SmoothDamp(currWeight, 1.0f, ref yVelocity, smoothTime);
animator.SetLayerWeight(1, startWeight);
}
public void UnarmedInactive ()
{
float endWeight = Mathf.SmoothDamp(currWeight, 0.0f, ref yVelocity, smoothTime);
animator.SetLayerWeight(1, endWeight);
}
}