Search Unity

Rotation of rays doesn't works right using Quaternion.AngleAxis (video included). SOLVED

Discussion in 'Scripting' started by orenog, Oct 19, 2019.

  1. orenog

    orenog

    Joined:
    Jan 9, 2016
    Posts:
    9
    Hi, this is my code with the problem:

    Code (CSharp):
    1.         Physics.Raycast(transform.position, Quaternion.AngleAxis(5, transform.right) * transform.forward, out tmoHit, 15);
    2.         Debug.DrawLine(transform.position, tmoHit.point, Color.blue);
    3.         Physics.Raycast(transform.position, Quaternion.AngleAxis(10, transform.right) * transform.forward, out tmoHit, 15);
    4.         Debug.DrawLine(transform.position, tmoHit.point, Color.blue);
    5.         Physics.Raycast(transform.position, Quaternion.AngleAxis(-5, transform.right) * transform.forward, out tmoHit, 15);
    6.         Debug.DrawLine(transform.position, tmoHit.point, Color.blue);
    7.         Physics.Raycast(transform.position, Quaternion.AngleAxis(-10, transform.right) * transform.forward, out tmoHit, 15);
    8.         Debug.DrawLine(transform.position, tmoHit.point, Color.blue);
    it suppose to cast rays with an offset of 5 degs.
    it works perfect for some rays, but others only work when on certian angles! I though I understood what I did wrong last time, and now it seems right, it's like I have a glitch in the brain ):

    here is a video of the problem:


    also, this worked for another axis, but I couldn't get it to work for the axis I needed, so this works:
    Code (CSharp):
    1.         Physics.Raycast(transform.position, Quaternion.Euler(0, 0, 0) * transform.forward, out tmoHit, 15);
    2.  
    3.         Physics.Raycast(transform.position, Quaternion.Euler(0, 10, 0) * transform.forward, out tmoHit, 15);
    4.  
    5.         Physics.Raycast(transform.position, Quaternion.Euler(0, -10, 0) * transform.forward, out tmoHit, 15);
    6.  
    7.         Physics.Raycast(transform.position, Quaternion.Euler(0, 25, 0) * transform.forward, out tmoHit, 15);
    8.  
    9.         Physics.Raycast(transform.position, Quaternion.Euler(0, -25, 0) * transform.forward, out tmoHit, 15);
     
    Last edited: Oct 19, 2019
  2. orenog

    orenog

    Joined:
    Jan 9, 2016
    Posts:
    9
    I am the stupidest person alive, it returned null because there was no hit, how stupid can I even be!!!?!?!?!?!?