Search Unity

Question [Starter assets] First person touch navigation - Custom camera angle via click

Discussion in 'Cinemachine' started by p2or_, Aug 15, 2023.

  1. p2or_

    p2or_

    Joined:
    Oct 16, 2020
    Posts:
    4
    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:

    Code (CSharp):
    1.  
    2.     ...
    3.     public void OnPointerDown(PointerEventData eventData)
    4.     {
    5.         RectTransformUtility.ScreenPointToLocalPointInRectangle(containerRect, eventData.position, eventData.pressEventCamera, out currentPointerPosition);
    6.         Vector2 positionDelta = GetDeltaBetweenPositions(new Vector2(0f, 0f), currentPointerPosition);
    7.         Vector2 clampedPosition = ClampValuesToMagnitude(positionDelta);
    8.         Vector2 outputPosition = ApplyInversionFilter(clampedPosition);
    9.         OutputPointerEventValue(outputPosition * .3f);
    10.  
    11.     }
    12.  
    13.     ...
    14.  
    This works somehow but do not result in the midpoint of the screen for whatver reason: https://drive.google.com/file/d/12NLkQUVkU8z-h7OoNBqUJGzsIvYTmyuo/view?usp=sharing

    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