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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

My raycast doesn't flip

Discussion in '2D' started by janjicm, May 13, 2020.

  1. janjicm

    janjicm

    Joined:
    Apr 29, 2020
    Posts:
    16
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Well you "flip" the direction by scaling it by the local scale so the pretty obvious question is; is the local scaling change as you expect? Obviously this is Local scale and won't change if you're changing the scale of the parent.

    Code (CSharp):
    1. Gizmos.DrawLine(pickup.position, new Vector3(pickup.position.x + distance, pickup.position.y, pickup.position.z));
    Also, your line draw isn't related to what you're doing in the raycast.


    Code (CSharp):
    1. Physics2D.queriesStartInColliders = false;
    Why are you changing this per-frame? Just set it once and it'll stay like that.
     
    janjicm likes this.
  3. janjicm

    janjicm

    Joined:
    Apr 29, 2020
    Posts:
    16

    ok only thing I got is that I should put "Physics2D.queriesStartInColliders = false;" in start, I'm brand new to this so I'm confused still lmao
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    The line you draw isn't the same as what you query.

    This option can be set globally in the project settings.

    Edit > Project Settings > Physics 2D > Queries Start In Colliders

    https://gyazo.com/9178818a7ee033ccc0562836bb260443
     
    janjicm likes this.
  5. janjicm

    janjicm

    Joined:
    Apr 29, 2020
    Posts:
    16
    Thanks about that! :D
    I guess I'll just give up on raycast for now lmao
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Not sure why you're giving up. If you know your "localScale" is changing then ensure you draw the ray to match what you query. Something like:
    Code (CSharp):
    1. Gizmos.DrawLine(pickup.position, pickup.position + new Vector3(transform.localScale.x * distance, 0f, 0f));
     
    Last edited: May 13, 2020
    janjicm likes this.
  7. janjicm

    janjicm

    Joined:
    Apr 29, 2020
    Posts:
    16
    I made it working with this:
    Code (CSharp):
    1.       Gizmos.DrawLine(pickup.position, pickup.position + (transform.right * distance));
    Thanks for your help, I really appreciate it :D
     
    MelvMay likes this.