Hi,
I am having two cubes in a bar I have attached draggable script in the cubes. while moving the cubes if the distance between the cubes is 0.5m I have to stop the user in moving the cubes lesser than 0.5m distance. my problem is if I am moving the cubes slowly there is no issues and if I am moving the objects fastly my objects is going lesser than 0.5m.
public void OnDrag(PointerEventData eventData)
{
ZPointerEventData pointerEventData = eventData as ZPointerEventData;
if (pointerEventData == null || pointerEventData.button != PointerEventData.InputButton.Left)
{
return;
}
Pose pose = pointerEventData.Pointer.EndPointWorldPose;
float v = Vector3.Distance(Lballoon.transform.position, Rballoon.transform.position);
//Debug.LogWarning(v);
if (v <= 0.5f)
{
if (activeDrag)
{
activeDrag = false;
maxdis = pose.position.x;
Debug.Log("MxDis Set " + maxdis);
}
}
float clampValue = Mathf.Clamp(pose.position.x, -1.11f, maxdis);
this.transform.position = new Vector3(clampValue, this.transform.position.y, this.transform.position.z);
}