Best practice for making blob shadow projector always face down?

I’ve come across 2 methods so far, one which involves making the projector a child of the object casting the shadow and then using this script on the projector itself:

function Update () {
    var facedown = Quaternion.identity;
    facedown.eulerAngles = new Vector3( 90, 0, 0);
    transform.rotation = facedown;
    }

Which sort of works… but seems to have weird artifacts when the parent object rotates - and the second method which involves copying the objects position information over to the projector’s position information:

var objectToFollow : Transform;
var offset : Vector3;

function Update () {
    transform.position = objectToFollow.position + offset;
}

I haven’t tried the second method yet, but I figure the projector can no longer be a child of the main object which sounds like it could become quite messy.

Any tips?

That 2nd method ROCKS!! I just place the projector into an epty game object placed at ground level with the projector above facing downwards, applied the script, assigned my character, SWEEETNESS it's simplicty at it's best!!

Very handy script, I did notice however that it casts the shadow in the wrong direction so it does not match up with my light mapped shadows, any way to fix that to make it more accurate? Also trying to figure out how to make it so as when my enemy character is destroyed that the blob shadow projector also gets destroyed because right now I get an error message: MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

Oh, and as for your second question... I would try making the shadow part of a Prefab, including both the character and the shadow projector. When the enemy needs to die, kill the whole Prefab. There are other ways to do this, too. For instance, you could have the Update() function include a check to see if the object is still in existence: if (!transform) <delete whatever>

I must be missing something it still places the shadows in the wrong direction?

Not sure what is happening then. In my project, the code works perfectly. Were there other lights involved in the lightmap? That could make it look like a different angle. If you mean the angle is wildly off - like, 90 degrees or something - there are deeper issues going on. But I hope that's not the case.

4 Answers

4

The second method is the way to go. Nothing messy about it :slight_smile:

If I’m instantiating the shadow casting object, where would you recommend I place the projector?

Do I instantiate it along with the object at the same time - or is there a way I can nest it in with the object-prefab as a child?

,I see, if I’m instantiating the shadow casting objects, would you advise that I also instantiate the shadow projector at the same time?

or could I make a prefab that contained both?

You should post this as a comment to my answer... not as an 'answer'

point taken!

Instantiate the shadow casting object, then instantiate the projector seperately.
It has no reason to be a child of of the object, as the rotation will cause problems.

I used this script for my car shadow, but the shadow does not rotate with my car!