I'm working with this code below to control the distance from the camera to the character, this distance is the result of linear interpolation between a minimum and maximum offset, where the variable float distance
controls this result.
Vector3.Lerp(minOffset, maxOffset, distance)
But in the zoom function the result of the Vector2.Distance
is being quite large, between 110,000 and 890,000, which is certainly far from the minimum and maximum required to control Lerp.
void Zoom()
{
if (Input.touchCount != 2)
return;
Touch touch0 = Input.GetTouch(0);
Touch touch1 = Input.GetTouch(1);
if(touch0.phase == TouchPhase.Moved || touch1.phase == TouchPhase.Moved)
{
distance = Vector2.Distance(touch0.position, touch1.position);
}
}
I've tried using Mathf.Clamp
, but logically the value of Vector2.Distance
is too large for the result to be less than 1F.
distance = Mathf.Clamp(Vector2.Distance(touch0.position, touch1.position), 0F, 1F)
How can I reduce the minimum and maximum from Vector2.Distance
to min 0F and max 1F?
Remember that I should consider that in some devices the result between touch0
and touch1
in Vector2.Distance
may be greater.