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

Help with a laser (solid beam)

Discussion in 'Scripting' started by suspensemusic, Jan 18, 2014.

  1. suspensemusic

    suspensemusic

    Joined:
    Dec 4, 2013
    Posts:
    41
    What method would I use to create a solid laser beam and have it stop at walls?

    I can make the beam I am assuming using the line renderer and some particle effects. I am not sure how I would stop the beam from going past my walls. Also I am not positive of how I would set a collider to the line (I'm not at home in Unity right now so that may be an easy thing to do I just can't see it right now)

    But I know that I don't know how to stop the beam. What would I need to do to make that happen?
     
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Shot a raycast, and scale your beam with its length?
     
  3. suspensemusic

    suspensemusic

    Joined:
    Dec 4, 2013
    Posts:
    41
    I need the beam to stop at walls.. So it doesn't shoot through that object.
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    A raycast stops at collider/collision. Isn't that what you want?
     
  5. suspensemusic

    suspensemusic

    Joined:
    Dec 4, 2013
    Posts:
    41
    so create a line renderer to scale to the length of the raycast and it will do what I am asking?
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    A line renderer, a cylindrical mesh, two planes in X... The rendering is up to you, but yeah, the raycast has an origin, and the RaycastHit has a point in space where it hits. Substract both, and you get a vector with the proper length.