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

How use Light as Raycast?????

Discussion in 'Physics' started by psyhova, Feb 8, 2015.

  1. psyhova

    psyhova

    Joined:
    Oct 3, 2013
    Posts:
    32
    Hello Guys

    Maybe anyone knows Commandos. I want to realize a Cone of View, but Raycast seems to be a bad solution for This.

    I want a spotlight. and If my enemy is lit by the Light, I want to do something. So what is the right way?????
    Do I have to check the shader on the specific Enemy, if ihe is lit by this specific Light???

    How does Unity regonizes if something is lit or not? Its the shader????

    Thanks
     
  2. Emre_U

    Emre_U

    Joined:
    Jan 27, 2015
    Posts:
    49
    Use a light and a collider. Try to mimik lit Area with collider. Use as trigger. It is not about light but knowing something is in that cone.
     
  3. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
  4. psyhova

    psyhova

    Joined:
    Oct 3, 2013
    Posts:
    32
    Thanks for link to cctv cameras do you kow?? It is dynamic??? Can I hide my player behind a obstacle?? So that he is not seen by the cctv????
    Thanks
     
  5. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    I think this is adressed in some of those videos too but I am not sure. What I would do - but I'm just a beginner with Unity - if the player gets into the camera zone/trigger then you have to do an extra check maybe by casting a ray or two or three from the center of the camera to the player position and if the first object hit is not the player then the player is hidden.

    See the docs: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html or maybe easier in your case: http://docs.unity3d.com/ScriptReference/Physics.Linecast.html

    You can also search on Youtube about Raycast to find how it is used.
     
  6. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    You might get the behaviour you want using a capsule cast rather than a raycast. The Physics.CapsuleCastAll function returns a list of all objects that fall within a capsule-shaped region of space (what you really want is a cone rather than a capsule, but the capsule is probably close enough to give the right effect in the game). Checking if an object is hidden from the camera is a bit more difficult. You might be able to approximate it by doing a raycast against one or more "significant" points on the object (eg, its centre and extremities) too see if they are blocked by other colliders in the way.

    If you need perfect detection of obscured/visible objects then you will probably need to render the view from a camera pointing in the same direction as the spotlight. If you render to a Render Texture you can analyse the resulting image to detect parts of objects that are visible (eg, render a character so that it appears in white while the other objects are black and then check the rendered image for any white pixels). This is quite an advanced technique, though, and it might be a bit too involved if you only need the detection to be approximate.
     
  7. codegforges

    codegforges

    Joined:
    Nov 24, 2015
    Posts:
    1