Unity & lurking in the shadows

The key feature for my Under the Shade (LD48 jam entry) was to make player be under a shade. I used two strategies. There was areas called “shade”, which were meant to provide decent shade. Not optimal, but something that stops dehydration (a feature that never got in the game due time limits…). This type of shade could be found under the trees or near big rocks. Another type of shade that I called “good shade” in the game. The “good shade” would be possible if there’s “something on top of a character”.

First I had trouble figuring out how to determine “if I’m under the shade”, but then I figured out a very simple solution: I clicked “create sphere”, and made the “collider” to be a “trigger”. Then I placed the shadearea to the place where I wanted to be. Here for example, I placed the area where the shadows are:

After that I placed a script called shadearea.cs to each shade area game object. For my purposes, I didn’t want this object to do anything except to inform when something enters or exits. So I basically wrote this (with the silly IF-statement, that should be got rid by for example ensuring that “player” is the only gameobject that can collide with the trigger).

public class ShadeArea : MonoBehaviour {

	void OnTriggerEnter(Collider other) {
		if (other.gameObject.tag == "Player") {
	void OnTriggerExit(Collider other) {
		if (other.gameObject.tag == "Player") {

After this, I could do something with the information (like make it so that player’s hydration value would be changed).

Naturally this approach was done for a jam entry, and there’s some obvious issues:
– If the position of the sun changes, the shade area should move. This could be done by checking out the central point (when the sun is highest) and then rotation/moving the shade area. Or we could just ignore this. Or we could do something else.
– Collision could inform “gameplayManager” or something like that, instead of the player. And the gameplayManager then could tell other objects that “player is in shadows” or not. This would be needed if there were other people in the game.
– I placed the shade area manually. Since I had only 2 of them in the game, I could handle. But if I was to create a random scenery or have 100 locations, I would definitely need to make the shadearea part of the gameobject.

And probably other issues too.

Since I didn’t have the time to make use of the feature (I dropped away ‘hydration’ feature since I had no time to test it), so the ‘shade near objects’ feature was dropped. But at least I learnt something when doing, and now perhaps this blog post helps somebody else in their projects.

Juuso Hietalahti


  1. nice and simple solution.
    you could use other.gameObject.COMPARETAG it more efficient then comparing strings.
    also using events should be better then sendmessage.
    for these who use it in real projects… i guess it just fine for game jam. :)


  2. Thanks for this haha, I’ve read up a lot on various shadow solutions for stealth games :) Was this in Unity Pro? Cos I thought only Pro could have shadows… But then your screenshots has a light grey interface, which means it’s not pro… Huh? How did you get shadows in not-pro in the first place? :O

    • I use the Indie/free version. I have one sunlight and there i turned on shadows. Rock game objects have “cast shadows” ON.

    • Unity Free started to offer simple shadows since version 4. (hard shadow)

Leave a Reply

Your email address will not be published. Required fields are marked *

Pro-Human Quiz: