0
I am working with this code below controlling 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 Vector2.Distance
is being quite large, between 110,000 and 890,000, which is certainly beyond the minimum and maximum necessary 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 quite 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 of the Vector2.Distance
at min 0F and max 1F?
Remembering that I must consider that in some devices the result between the touch0
and touch1
in the Vector2.Distance
may be greater.
You have a script that does something similar to this in the Asset Store: https://www.assetstore.unity3d.com/en/#! /content/14489 .
– Daniel Dourado