- Home /
Blob Shadow
Ok, how can I make my blob shadow that was included with the unity package follow the player and not to rotate with it, I want it to follow the shape according to the terrain. How can I do that.
Felipe
what do you mean by follow it but not rotate with it. Do you want it to be vertically above the character looking down on it the whole time or... What?
Its becuase my character is rolling ball and if a shadow is a child of the ball then obviously it will rotate with it too
Answer by ActionScripter · May 24, 2012 at 04:04 PM
I had exactly this problem, but I was able to put together a robust solution based on various community answers. I think it will work for you.
Create a blob shadow projector (I think one comes in standard assets). Then slap this script on it. Once you point the variables to the player and the sun/light source in the inspector, it will work like a charm.
// 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 Peter G · Feb 04, 2012 at 11:09 PM
The easiest thing to do is just parent the player to the blob shadow. That is place the blob where you want it relative to your object, then make it a child of the object. Then whenever you move the character, the shadow will follow.
Thaks but i wnat it to move the shadow with the player but not to rotate with it
Answer by luniac · Feb 13, 2013 at 04:39 AM
Ok I don't know how the hell that other script is supposed to function, but here's mine.
The "5f" value affects how high above the ball the shadow projector is, you can change it to whatever you like, it affects how much the size of the shadow changes with distance from floor. Actually the commented out code is the original "transform.position = transform.parent.position + Vector3.up * 15f;"
Make sure the projector is a child of the ball.
//BlobShadowController.cs
using UnityEngine;
using System.Collections;
public class BlobShadowController : MonoBehaviour
{
void Update()
{
transform.position = transform.parent.position + Vector3.up * transform.parent.localScale.y * 5f;//* .50f;
// transform.position = transform.parent.position + Vector3.up * 15f;
// Debug.Log(transform.position);
transform.rotation = Quaternion.LookRotation(-Vector3.up, transform.parent.forward);
}
}