Hi, I’m using crossplatform joystick and I want to clamp it to it’s max range so it will only move in a circular with center pivot.
Here is the code for clamping from standard assets
public void OnDrag(PointerEventData data)
{
Vector3 newPos = Vector3.zero;
if (m_UseX)
{
int delta = (int)(data.position.x - m_StartPos.x);
newPos.x = delta;
}
if (m_UseY)
{
int delta = (int)(data.position.y - m_StartPos.y);
newPos.y = delta;
}
transform.position = Vector3.ClampMagnitude( new Vector3(newPos.x, newPos.y, newPos.z), MovementRange) + m_StartPos;
UpdateVirtualAxes(transform.position);
}