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
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.
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;
}
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.
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);
}
}