- Home /
How to play animation based on Pinch in/out values?
Hi, I have a 3D object which has 2 Animation clips (Explode/Implode). Each clip is about 60 frames. Now when i do Pinch-in on my mobile-touch, Explode animation clip should play according to how much i pinched-in (Based on the pinch value, need to play the animation clip-frames).
If i moved the two fingers little, then the animation also should be played little. Vice-versa for Pinch-out for Implode animation. And the animation should stop playing when the fingers are off.
Could you please help me or give a tip on how to synch the pinch value and animation clip's frames.
Thanks
Jeeva
When i said Explode/Implode, I dint mean about Explosion (particles). I meant about assemble and disassemble. Herewith attaching Sample Explode/Implode Images.
Answer by abi-kr01 · Jun 22, 2015 at 02:30 PM
As far as i i know animation play in full length like when i say gameobject.animation.play("Explode"); it will play the the animation .if you pause the animation it will pause but replay will be from start.
there are two ways we can do that
1)If its only a placement thing we can use Lerp for that
2)divide the animation in several parts and run them differently
Hi abi.kr
Thanks for your valuable time and reply, I am trying to use Lerp only. I dint get still. Let me try.
Hi abi.kr01,
Thanks for your concern. I have not yet solved the problem. I am just following the tutorial,
https://cgcookie.com/unity/lessons/3-detecting-2-finger-gestures/
by $$anonymous$$ Bilz for pinch in/out. $$anonymous$$y script now looks something like this:
function Update () {
if(Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved && Input.GetTouch(1).phase == TouchPhase.$$anonymous$$oved)
{
v2_current = Input.GetTouch(0).position - Input.GetTouch(1).position;
v2_previous = (Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition);
f_touch_delta = v2_current.magnitude - v2_previous.magnitude;
animGO.animation.enabled = true;
animGO.animation["Assemble"].time = 0;
animGO.animation["Disassemble"].time = 0;
if($$anonymous$$athf.Abs(f_touch_delta) > f_comfortZone)
{
//zoom in
if(f_touch_delta>0) //changing everyframe
{
if(animGO.animation["Disassemble"].time <= disTF)
{
if(isPlaying == false)
{
animation["Disassemble"].time = $$anonymous$$athf.Clamp($$anonymous$$athf.Lerp(animation["Disassemble"].time, animation["Disassemble"].time - $$anonymous$$athf.Abs(f_touch_delta), Time.deltaTime),0,50);
animation["Disassemble"].speed = 1;
animation.Play("Disassemble");
isPlaying = true;
}
}
}
else
{
if(animGO.animation["Assemble"].time <= assTF)
{
if(isPlaying == false)
{
animation["Assemble"].time = $$anonymous$$athf.Clamp($$anonymous$$athf.Lerp(animation["Assemble"].time, animation["Assemble"].time + $$anonymous$$athf.Abs(f_touch_delta), Time.deltaTime),0,50);
animation["Assemble"].speed = 1;
animation.Play("Assemble");
isPlaying =true;
}
}
}
}
I am just trying to pass the value to -> animation["ClipName"].time by clamping and lerp, using the touch $$anonymous$$agnitute (touch_delta) and animation time.
Not getting as expected though. thanks
Your answer
![](https://koobas.hobune.stream/wayback/20220613200811im_/https://answers.unity.com/themes/thub/images/avi.jpg)