Search Unity

RacastHit return always -Vector3 up

Discussion in 'Physics' started by ndbn, Jun 29, 2019.

  1. ndbn

    ndbn

    Joined:
    Jan 19, 2018
    Posts:
    13
    Hi,
    I have a gameObject with a script, and camera that can move in two ways.
    -Rotate around an object
    -Horizzontal and Vertical
    With mouse you can select the move.

    But when the 2nd kind of movement it end, i need to assign another point to see for rotate around it.
    When the button is up call the script below.
    But hit.transform.position is always 0,-1,0
    I paid attention to hit a big cube that now use as test terrain.
    Thx for help ^^

    Code (CSharp):
    1.         Camera camera = this.GetComponent<Camera>();
    2.         Vector3 vector = Vector3.zero;
    3.         if (Physics.Raycast(this.transform.position,this.transform.forward, out RaycastHit hit, 100))
    4.             vector = hit.transform.position;
    5.         return vector;
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,447
    hit.transform.position returns position of the transform, maybe you wanted hit.position ?
     
    ndbn likes this.
  3. ndbn

    ndbn

    Joined:
    Jan 19, 2018
    Posts:
    13
    Yeah, i tryed to use hit.collider.tranform.position but always the same story :(

    EDIT:

    I'm novice XD
    I need write a simple hit.point :D
    Thx
     
    Last edited: Jun 29, 2019