Search Unity

Creating a Flashlight Effect!

Discussion in 'Scripting' started by uistudios, Apr 9, 2009.

  1. uistudios

    uistudios

    Joined:
    Apr 6, 2009
    Posts:
    46
    Can someone show me how to make a flashlight effect in unity... just simply take an object like cylinder and attach a spotlight to it... I think it would be a great simple tutorial for all the newbies here!
     
  2. Doo 2000

    Doo 2000

    Joined:
    Apr 5, 2009
    Posts:
    60
    I tried to juyst make a cylinder and attatch a spot light to itm, but it failed. I hope someone helps me too.
     
  3. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    If all you need is to make the area you are lighting brighter then the rest of the scene (Without actually seeing the beam) then all you need is a game object with a spot light attached to it.

    Of course, if you want that distinctive circular shape that is created - you need to have your scene use diffuse shading, and have your flashlight forced to be a pixel light.

    Plus - have the light cast shadows (if you have Unity Pro) to see the full effect in action.

    About the shaders - it's pretty straight forward. Select the objects your scene is made of, and make sure that in their materials, the shader that is selected is Diffuse and not Vertex-Lit.

    About the light (obviously make sure it's of type spot and not directional or pixel) - select your light, and in the inspector make sure that under "Render Mode" you have "Force Pixel" selected.

    If you want - add a cookie texture to make those artifacts that you see when you use a real life flashlight. The ones that make ring-like features on the objects you are pointing the light on...

    If you want to actually see the beam - like when your room is dusty, and the light is visible, then you'll need a little more work. A mesh for the cone that will be semi-transparent, and maby some shader/particles work if you want that "dusty" effect.

    If you're having troubles, just post and i'll try and help out... No time for a full tutorial thought... :/
     
  4. beezir

    beezir

    Joined:
    Apr 3, 2009
    Posts:
    133
    You could also just attach a spot light to an object and narrow the spot angle to something like 5 degrees. I think you'll want to make sure that the surfaces (like terrain) use pixel lighting in that case, or else it'll light up a lot more than you want.

    You get something like this:



    EDIT: Whoops, misread the previous post. He did in fact suggest a spot light exactly like this. :oops:
     
    Last edited: Feb 15, 2011
  5. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    No biggie. At least they got a screenshot as a reference now :)
     
  6. Doo 2000

    Doo 2000

    Joined:
    Apr 5, 2009
    Posts:
    60
    thnx, it helped.
     
  7. alsharefeeee

    alsharefeeee

    Joined:
    Jul 6, 2013
    Posts:
    80
    You can use the projector.