Hello! I’m having a problem with interpolating a value that constantly changes - pelvis rotation on x axis for procedural animation. When the character goes up I want them to bend forward and when descending they should bend backward a little. The character now knows when going up or down and somehow choppily bends but I just CAN’T make the movement smooth! I’m no programmer and it’s probably something absolutely stupid. I’ll be super grateful for any help ![]()
Here’s the code (clean, without all the interpolation stuff I tried)
private void Start()
{
anim = GetComponent<Animator>();
InvokeRepeating("PrevPos", 0, 0.2f);
}
called from OnAnimatorIK:
newPelvisRotation = anim.bodyRotation.eulerAngles + whyunotwork;
anim.bodyRotation = Quaternion.Euler(newPelvisRotation); //<MAKE THIS SMOOTH
}
void PrevPos()
{
previousPositionY = transform.position.y;
Invoke("CheckPos", 0.2f);
}
void CheckPos()
{
RaycastHit hitRay;
Physics.Raycast(transform.position, Vector3.down, out hitRay, 2f);
groundSlopeAngle = Vector3.Angle(hitRay.normal, Vector3.up);
if (transform.position.y < previousPositionY)
{
groundSlopeAngle = -groundSlopeAngle;
}
whyunotwork = Vector3.right * groundSlopeAngle;
}