Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RayCast around the object

Discussion in 'Scripting' started by Rutenis, Apr 18, 2015.

  1. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Hey, so i ran across this little problem, i dont know how to raycast around my player. At this point i can only raycast at the top, here is the example:

    Heres the code, its pretty straitght Forward:

    Code (csharp):
    1.  
    2. for(float i = 0; i < amount; i += 0.25f)
    3.         {
    4.             Vector2 pos = new Vector3(posX + i, posY, 0);
    5.             RaycastHit2D hit = Physics2D.Raycast(transform.position, pos, distance);
    6.             Debug.DrawRay(transform.position, pos, Color.red);
    7.  
    8.             if (hit.collider != null)
    9. {
    10. //More Code.....
     
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
  3. Rutenis

    Rutenis

    Joined:
    Aug 7, 2013
    Posts:
    297
    Nah unfortunatealy thats not what i need, i need to get normals.