Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player direction & Cross-Hair

Discussion in 'Scripting' started by Welly10, Feb 1, 2022.

  1. Welly10

    Welly10

    Joined:
    Aug 13, 2021
    Posts:
    38
    I've created a crosshair with (UI - Image(duplicate image & create crosshair))
    I've installed the animation rigging to make the character move correctly while aiming
    and when I put in the source object of the animation rigging (crosshair) the player always look as you see
    can anyone explain to me what I'm doing wrong
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Are you raycasting through the crosshair to the impact point and setting that as your target?
     
  3. Welly10

    Welly10

    Joined:
    Aug 13, 2021
    Posts:
    38
    When I raycast through the crosshair the character keep looking up at the center of the canvas
     
  4. Welly10

    Welly10

    Joined:
    Aug 13, 2021
    Posts:
    38
    Code (CSharp):
    1. mouseWorldPosition = Vector3.zero;
    2.  
    3.         Vector2 screenCenterPoint = new Vector2 (Screen.width / 2f, Screen.height / 2f);
    4.         Ray ray = Camera.main.ScreenPointToRay(screenCenterPoint);
    5.         if (Physics.Raycast(ray, out RaycastHit raycastHit, 800f, aimColliderMask))
    6.         {
    7.             debugTransform.transform.position = raycastHit.point;
    8.             mouseWorldPosition = raycastHit.point;
    9.         }
    that code is attached to the player
     
  5. Welly10

    Welly10

    Joined:
    Aug 13, 2021
    Posts:
    38


    that is what I've reached so far