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. Dismiss Notice

[CLOSED] Shadow & stealth. Shadows hide player from AI.

Discussion in 'Scripting' started by Lahzar, Feb 21, 2015.

  1. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Greetings, ladies and gentle! I apologize in advance for a long post!

    I wanted to make a good stealth system for my extensive tech demo. I want something different than normal stealth games nowadays. I want something like the old Theif game or old splintercell stealth, where shadows would actually conseal you. Its a cool idea. But from what I've heard about unity, its not possible to do?
    So first question: Is it even possible?

    I did some research and found this forum post: http://answers.unity3d.com/questions/24662/detect-lightshadow-falling-on-object.html I tried to do what it says about rendertextures, but I dont know how.

    I set up a 32x32 rendertexture from my AI's camera, rendering only the player. But I am not able to access it from my script it seems(, not sure). I simply added a grayscale image effect so that I only need to check the white/black value of the pixels, but I dont know how to do that either. Also when I set the AI cam to player only, the lights that shine on it goes trough walls, is this fixable?

    TLDR:
    Is it possible to check how lit up an object is using rendertextures and checking the pixels colourvalues?
    How do I access a rendertexture from a script properly?
    How do I make a rendertexture into a normal texture2D?
    How can one check the brighness or white/black colour value of a rendertexture?
    How do I keep the shadows from other layers when a camera only renders the player?
    Is there a better way to do all this?
     
  2. Timelog

    Timelog

    Joined:
    Nov 22, 2014
    Posts:
    528
    I don't know if it is possible to do it with light/shadow detection, or the by checking colorvalues. But, as you generally want to bake the lighting anyway, it is also a possibility to just place triggers in shadow spots that set a bool whether you are hidden or not. That way, when an enemy "detects" you, he can just check if he should ignore you or not.

    Might be a bit "hacky", but something to keep in mind if there are no better options.
     
    Lahzar likes this.
  3. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Placing triggers in the shadows would work great, sure. But I want to be able to deactivate certain lights in certain ways, and it would just be a pain in the arse to place triggers in the right way. This isnt something that must be done, Im just making a neat tech demo as a hobby, not a full game. Its more as a learning experience.


    I found this: http://answers.unity3d.com/questions/276890/converting-a-rendertexture-to-a-texture2d-for-use.html
    I have not tried this yet, but I will soon. If this works then the next step is to check all the pixels in the texture. Can one use texture2D.getPixels for this? I dont really know how getPixel works, but hopefully someone can elaborate?

    Quick update:
    I have managed to convert a rendertexture to a texture2D. Now I only need to check all the pixels for how white they are. Any help?
     
    Last edited: Feb 22, 2015
  4. Lahzar

    Lahzar

    Joined:
    May 6, 2013
    Posts:
    87
    Well, I managed to do this on my own... Sorry for a waste of time people.
     
    Last edited: Feb 24, 2015
  5. attaway

    attaway

    Joined:
    Nov 12, 2014
    Posts:
    45
    It's been a few years, but what route did you end up taking?
    I'm working on a similar game and have been looking at different ways to detect lighting.