- Home /
Float Count Up & Count Down
Hello all! Ive been messing around with UMA but I have a fairly simple problem haha. I want to make a float basically go from -1.0f to 1.0f, & then back from 1.0f to -1.0f and stay idle until the mouse is clicked again, a simple loop counter.. So here is my script, free cookies to those with empty tummys <3
if (Input.GetMouseButtonDown (0)) {
m_Animator.SetTrigger ("Attack");
mouthclose = false;
mouthopen = true;
}
//OPENS MOUTH ON CLICK (For Yell)//
if (m_uma.mouth >= -1.0f && mouthopen == true && mouthclose == false && m_uma.mouth <= 1.0f) {
m_uma.mouth += Time.deltaTime;
mouthclose = true;
mouthopen = false;
}
Answer by stepan-stulov · Aug 20, 2015 at 08:39 AM
You can always create an animation that controls a custom property between -1 and 1 and that then by code is reflected into the mouth wideness. You can then reshape the animation curve for smoother less scripted & robotic appearance. It seems more natural than code-only approach.
Answer by convictcartel · Aug 20, 2015 at 08:51 AM
Im not sure what you mean to animate, in a new program itself? The jaw looks natural with the time lerp I have but its not correct I cant get it to go back & stop moving.
Please post this as a comment to an answer, not as a new answer.
I have no idea what you mean by a "new program itself". To animate is to control a property via the Animator. You declare a serialized property and let an animation curve control its value over time.
By using += Time.deltaTime you only increase the value of the property, and never decrease. You would want to decrease when the direction of the mouth movement is from open to close. The thing is, what you do IS an animation controlled mouth. It's just the animation is programmatic, linear and highly uncustomizable. There kind of is a flat and ever rising animation curve in your head reflected onto the code. Such artistic things simply don't belong in code, the belong in the animator. It's like making a skeleton animation with iTween - an unexpected and extremely hardcoded (read bad) solution.