I want to visualise a pinch grasp of a real hand. The only thing I measure is the distance between thumb and index finger.
I made some pinch grasp animations of my virtual hand model in Maya, because I think I can make the grasp look more realistic by animation than by directly accessing the transforms. The animations look quite good in unity.
To apply the measured distance of the fingers to the virtual hand, I simply calculated the corresponding animation time for every frame and played the animation. This works, but seems to be quite dirty.
Is there a possibility to simply transform the model to an animation state without actually playing the animation? Or can you think of any other solution to solve my problem?
Hi, welcome to the forum!
The AnimationState class also has a normalizedTime property that can be set to a fraction between 0 and 1. This indicates a fraction of the total runtime of the animation. If this doesn’t help with what you’re doing, perhaps you could post the code you are using to get the finger positions and control the animation?
Here is my code that works (So far I take the finger_distance from the input):
function Update () {
dist += Input.GetAxis ("Horizontal") * input_pinch_speed;
if(Mathf.Abs(dist) > smooth) {
finger_distance = Mathf.Max(0,Mathf.Min(1,finger_distance + dist));
dist = 0.0;
if(finger_distance > pinch_distance_max)
{
animation["right_hand_pinch"].normalizedTime = (finger_distance - pinch_distance_max) * 2;
animation.Play("right_hand_pinch");
}
else
{
animation["right_hand_prepare_pinch_pos"].normalizedTime = finger_distance * 2;
animation.Play("right_hand_prepare_pinch_pos");
}
}
else
animation.Stop();
}
Maybe I’m doing the right thing, but I thought it would be nicer to have something like that (pseudo-code):
function Update () {
if(finger_distance changed)
{
if(finger_distance > pinch_distance_max)
this.transform = animation["right_hand_pinch"].state(finger_distance * 2);
else
this.transform = animation["right_hand_prepare_pinch_pos"].state(finger_distance);
}
}