Hi folks,
I’d like to extend the ‘Touch Zones’ canvas prefab so that the camera can be rotated to the current pointer position when the user clicks the screen. Or in other words: center the camera around any point of interesst (without moving the capsule or its camera root).
I tried to customize the ‘OnPointerDown’ method inside the ‘UIVirtualTouchZone.cs’ component associated with the ‘UI_Virtual_TouchZone_Look’ component:
...
public void OnPointerDown(PointerEventData eventData)
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out currentPointerPosition);
Vector2 positionDelta = GetDeltaBetweenPositions(new Vector2(0f, 0f), currentPointerPosition);
Vector2 clampedPosition = ClampValuesToMagnitude(positionDelta);
Vector2 outputPosition = ApplyInversionFilter(clampedPosition);
OutputPointerEventValue(outputPosition * .3f);
}
...
This works somehow but do not result in the midpoint of the screen for whatver reason: Screen Recording 2023-08-15 at 13.23.22.mov - Google Drive
Q: How can I rotate the player (camera) so that the clicked position gets properly transformed to the center of the screen?
Any help is appreciated, thanks.
Christian