Blob shadow going through multiple objects.

Since i am using Basic Unity, I’m limited to use the Blob Shadow Projector. It has worked fine for me until now, because of the following:

In one of the scenes, i have a few platforms, which are a few units above other objects, including a Terrain.

My problem is, the projector casts the blob shadow on any surfaces within the range of the projector. I tried to use a Spotlight instead, but unsuccessfully, because black is 100% transparent.

How do i prevent the blob shadow from being projected on multiple surfaces without sacrificing projection on slopes?

The blob shadow was placed as a component on a Ball-shaped player.
Edit: Here’s a screenshot:

http://i55.tinypic.com/73jxo5.png

I think there is no way to cast shadow only on the first hit object for free.

You can simulate it by changing the projector’s range dynamically, however, this can cause awkward effects in many cases.

If that’s ok for you, write a script like below and attach it to the parent GameObject of Blob Shadow Projector.

ShadowClipper.js

var shadowProjector : Projector; // the shadow projector
var shadowDistanceTolerance : float = 0.5; // positive number used to cast shadow on terrains correctly

private var origNearClipPlane : float;
private var origFarClipPlane : float;

function Start() {
    if(!shadowProjector) shadowProjector = transform.GetComponentInChildren.<Projector>();
    origNearClipPlane = shadowProjector.nearClipPlane;
    origFarClipPlane = shadowProjector.farClipPlane;
}

function Update() {
    var ray = new Ray(shadowProjector.transform.position
            + shadowProjector.transform.forward.normalized * origNearClipPlane,
            shadowProjector.transform.forward);

    var hit : RaycastHit;
    if (Physics.Raycast (ray, hit, origFarClipPlane - origNearClipPlane,
            ~shadowProjector.ignoreLayers)) {
        var dist = hit.distance + origNearClipPlane;
        shadowProjector.nearClipPlane = Mathf.Max(dist - shadowDistanceTolerance, 0);
        shadowProjector.farClipPlane = dist + shadowDistanceTolerance;
        //Debug.Log("Ray hit at: " + hit.point + ", distance: " + dist);
    }
}

All right, not sure how much of an answer this is, as I’m not 100% for what you’re using. But if you’re using a light, I would look into culling masks. You should be able to select what type of object it will project onto. Hope this helps.

#pragma strict

var shadowProjector : Projector; // the shadow projector
var shadowDistanceTolerance : float = 0.5; // positive number used to cast shadow on terrains correctly

private var hit : RaycastHit;
private var dist : float;            
private var origNearClipPlane : float;
private var origFarClipPlane : float;
private var ray : Ray;

function Start() {
    if(!shadowProjector) shadowProjector = transform.GetComponentInChildren.<Projector>();
    origNearClipPlane = shadowProjector.nearClipPlane;
    origFarClipPlane = shadowProjector.farClipPlane;
	
}

function Update() {
    ray = new Ray(shadowProjector.transform.position
            + shadowProjector.transform.forward.normalized * origNearClipPlane,
            shadowProjector.transform.forward);

    
    if (Physics.Raycast (ray, hit, origFarClipPlane - origNearClipPlane, ~shadowProjector.ignoreLayers)) 
    {
        dist = hit.distance + origNearClipPlane;
        Debug.Log(dist);
        
        //shadowProjector.nearClipPlane = Mathf.Max(dist - shadowDistanceTolerance, 12);
        
        //dist = 12 for large ball
        if(dist >= 12)
        shadowProjector.nearClipPlane = 15;//value higher than 12
        else
        shadowProjector.nearClipPlane = origNearClipPlane;
        
        shadowProjector.farClipPlane = dist + shadowDistanceTolerance;
        //Debug.Log("Ray hit at: " + hit.point + ", distance: " + dist);
    }
}

Hi
I’m new to Unity but have had similar problems, take a look at this:

This may help if you can dynamically change which layers it should ignore. Let me know if this works as this may be useful when I get further with my Unity project.
Thanks

Maybe if you can use a ray cast to find the object directly beneath you and enable this in the layer while disabling the last object the ray cast found?

Found this as well: change layer of child - Questions & Answers - Unity Discussions
Hope this helps!

I haven’t been able to try unity in depth yet, but I know photoshop. not sure if this will work, but if you were doing something like that in PS you would create 2 copies of the shadow and cut away the part you dont want showing through the platform.