- Home /
Blob Shadows - Reversing Shadow Effect?
Hi, I have a question relating blob shadows that I've come across.
Just starting, I am able to attach blob shadows to objects, and get a blob shadow to move with it. I have also looked at another question's script, which forces the blob shadow to always face downward even though its parented to another object. I have also been able to ignore layers, so the shadow will not be displayed on the object itself.
The blob shadow gets bigger when the object moves away from a surface. What I want is the blob shadow to get smaller as it moves away. This'll make the blob shadow appear from nowhere, rather than a large black dot appearing, before it shrinks and the object lands.
I hope you guys can help! :D
Answer by anomalous_underdog · Oct 03, 2010 at 11:54 AM
You need code that makes the projector move downwards when the object moves upwards.
Paste this code to a new C# script. Assign it to your object, then drag and drop the blob shadow projector to the script's shadow property.
EDIT: Doing the changes required by Biendeo was harder than I thought, but eventually I figured out a solution.
using UnityEngine; using System.Collections;
public class InverseYMovement : MonoBehaviour { public Transform shadow; public float characterHeight = 5.0f;
private float initialY = 0.0f;
private float groundHeight = 0.0f;
void Start()
{
initialY = shadow.transform.position.y;
}
void LateUpdate()
{
Vector3 pos = shadow.transform.position;
pos.y = groundHeight + initialY - (transform.position.y - groundHeight);
shadow.transform.position = pos;
RaycastHit hit;
int groundLayers = 1 << 0; // put here the layer where the ground/platforms are
if (Physics.Raycast(transform.position + new Vector3(0, characterHeight, 0), -Vector3.up, out hit, Mathf.Infinity, groundLayers))
{
groundHeight = hit.point.y;
}
}
}
Great, Underdog, I was looking for something like that a while ago!
This does work for the most part for me, but I'm making a platformer, and the character will jump up onto a ledge, but the shadow will become smaller. Is there any way to fix it so the shadow looks the same no matter at what altitude the player is at?
@Biendeo: I thought you wanted the shadow to get smaller as the character jumps. If you want it to stay the same size always, forget about the script I showed and just make sure the Orthographic property is checked on the projector component.
I should clarify what I said. I do want the shadow to become smaller as the player moves away from the ground. However, when playing my game, the projector will move closer to the ground when the player stands on a higher ledge, eventually reaching a point where the projector will move below the platform itself. I wanted to ask how to reset the projector's position when the player moves over a new platform.
@Biendeo: Ok, now I understand. initialY will need to be changed everytime the character lands on the ground/platform. I'm not on my dev machine right now, so I'll edit the code when I get the chance.
Your answer
Follow this Question
Related Questions
[Unity3D 3.5.6f4] Get rid of shadow projector artefact 1 Answer
Do blob shadow projectors work on iPhone? 1 Answer
Projector LookAt Player 2 Answers
Blob shadow problem 2 Answers