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!!
– anon48034950Very 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.
– anon48034950Oh, 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>
– ActionScripterI must be missing something it still places the shadows in the wrong direction?
– anon48034950Not 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.
– ActionScripter