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

How can I draw a random squiggly line? Need urgent assistance!!

Discussion in 'Scripting' started by scordymax, May 27, 2020.

  1. scordymax

    scordymax

    Joined:
    Aug 18, 2019
    Posts:
    4
    Good Day All,

    I would like to draw a constant random squiggly line at runtime.
    Each time I run it, it needs to generate a new random squiggly line.
    Preferably the line needs to keep drawing all over the place for about 5 seconds.

    Please could someone assist me urgently, trying to get this project done and am struggling alot.
    Thank you
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
  3. scordymax

    scordymax

    Joined:
    Aug 18, 2019
    Posts:
    4
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    GL.LINES has nothing do do with mouse input. Read the example again. They have an example that draws something based on mouse input, but you can make it do whatever you want.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,748
    A LineRenderer with positions being set randomly every Update is probably easier to do than futzing around with GL.LINES.

    We could give more specific advice if you were more specific about your goal. Like, is this a lightning effect? Is it centered around a particular object, in a particular space, or literally covering the entire screen at random?
     
  6. scordymax

    scordymax

    Joined:
    Aug 18, 2019
    Posts:
    4
    Well for art, have you ever heard of people taking a pencil and drawing a squiggly line over and around itself.
    Then spend time looking at the mess to find some sort of form to start a drawing?
    Well I want an automated digital version of this for myself.
    I want to be able to click a button and have a random squiggly line drawn each time.
    I have attached an example of what i want the result to look like.
     

    Attached Files:

    • Line.jpg
      Line.jpg
      File size:
      108.1 KB
      Views:
      332
  7. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I would:
    1) Figure out how to draw a single line
    https://docs.unity3d.com/Manual/class-LineRenderer.html
    https://docs.unity3d.com/ScriptReference/LineRenderer.SetPositions.html
    2) Figure out how to generate a random coordinate
    https://docs.unity3d.com/ScriptReference/Random.Range.html
    https://docs.unity3d.com/ScriptReference/Vector3-ctor.html
    3) Now draw a single line by generating two random coordinates for the start/end of the line
    4) Now add additional random vertices to make the line go all over the place
    5) Now you've got a lot of hard V shaped corners in the line, write a method for creating a series of vertices to generate a smoother curve to the line to replace the hard corners

    Done
     
    PraetorBlue and DaDonik like this.
  9. scordymax

    scordymax

    Joined:
    Aug 18, 2019
    Posts:
    4
    Thanks Joe, this sounds like a good idea. I am an Artist so this is all new to me.
    I think maybe im trying to accomplish more than I actually know how to.
    I will definitely attempt to try what you said, hope i come right :>
    Thank you for the reply ;)
     
    Joe-Censored likes this.