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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

RayCastHit2d

Discussion in 'Scripting' started by squarelife, Sep 4, 2018.

  1. squarelife

    squarelife

    Joined:
    Nov 8, 2017
    Posts:
    41
    Hi, I am trying to go through the free tutorial on the unity webpage.
    I have this code that is from the Rogue Tutorial that doesnt make sense to me.
    Apparently Physics.LineCast returns a Bool.(According to Unity docs)
    So how come they do this?
    RAYCASTHIT2d is not a bool.


    Code (CSharp):
    1. protected bool Move (int xDir, int yDir, out RaycastHit2D hit)
    2.        {
    3.      
    4.             hit = Physics2D.Linecast (start, end, blockingLayer);
    5.        
    6.            //Re-enable boxCollider after linecast
    7.             boxCollider.enabled = true;
    8.        
    9.            //Check if anything was hit
    10.             if(hit.transform == null)
    11.            {
    12.          
    13.            }
    14.             return false;
    15.        }
    iT'S from this tutorial
    https://unity3d.com/fr/learn/tutori...-tutorial/moving-object-script?playlist=17150
     
  2. squarelife

    squarelife

    Joined:
    Nov 8, 2017
    Posts:
    41
    I found the answer.
    Physics.Linecast returns a bool
    Physics2d.linecast returns a raycasthit2d
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,599
    Yeah, good catch... there's a ton of similiar "close but not quite exact" things you have to watch out for when working with Unity physics, since it's super easy to be looking at a 3D physics function and thinking you're looking at a 2D physics function!
     
    squarelife likes this.