- Home /
How to make a blob shadow project from a fixed angle as the object rotates?
If I have a blob shadow projector directly above my player object, and therefore the shadow directly below it, it works fine. But I want the sun to be not directly overhead but fixed at a slight angle. If the shadow projector is at an angle and parented to the player object, the blob shadow stays at that same relative angle and rotates around with the player object; not the effect I was looking for. I'm trying to make it follow the position but not the rotation.
Answer by Eric5h5 · Mar 21, 2010 at 04:17 AM
Don't use parenting, but instead use a script that makes one object follow another object without rotating:
var objectToFollow : Transform; var offset : Vector3;
function Update () { transform.position = objectToFollow.position + offset; }
Great stuff! Works for me although I didn't see the need for the offset variable :)
I found this answer recently (because I had the same question), and I would like to offer an improved version that automatically orients the shadows to the sun's angle. Simply slap this code on a blob shadow projector, assign the variables in the inspector, and you're good to go!
(Note: this can be adapted to work with point lights. You would simply need to replace the Start code with a line in Update that gets the vector from the point light to the object.)
// ShadowFollow.js
#pragma strict
var objectToFollow : Transform; // The object you need a shadow under
var offset : Vector3; // How much to shift the projector from the object center
var lightSource : Light; // What light is "casting" the shadow
function Start () {
transform.rotation = lightSource.transform.rotation;
}
function Update () {
transform.position = objectToFollow.position + offset;
}
Answer by Datael · May 25, 2012 at 06:14 PM
I have an alternative suggestion (and it will probably seem quite unusual) that uses parenting and will regrettably give you one extra game object, but it saves you from having to code at all.
If you create a new game object, call it, say, "Player Host" or something similar. Place the player object inside of this object at (0, 0, 0), then the object you want to follow it inside with it also. Now make your player move movement scripts target the host object, and the rotation scripts target the player object.
It's a bit convoluted but it will save you headaches in the long run. This theory can be applied in many situations, say if you wanted to make a planetarium.
Your answer
Follow this Question
Related Questions
Blob shadow changes transparency 2 Answers
Do blob shadow projectors work on iPhone? 1 Answer
Projector (Blob Shadow) does not work properly 1 Answer
Blob shadow problem 2 Answers
[Unity3D 3.5.6f4] Get rid of shadow projector artefact 1 Answer