Calculate the size of the shadow
1 answer
I suppose your question will be mostly from Exchange Math Stack , but here's an approach that I hope will lead you in the right direction.
Following are the following hypotheses:
- You know the height of the object when scale = 1
- your object is not too big (or you will need to include half its width in the math)
- your object is at its base (on a person: underfoot).
- your object is placed on the floor (and therefore not in the air: otherwise it is a little harder to calculate, but the idea remains the same)
Here's a quick outline of the situation:
Now you can calculate your shadow size using something like this:
Vector3 topPoint = YOUR_OBJECT.transform.position + YOUR_OBJECT.transform.lossyScale.y * YOUR_OBJECT_HEIGHT;
Vector3 lightFlatPoint = new Vector3(YOUR_LIGHT.transform.position.x, topPoint.y, YOUR_LIGHT.transform.position.z);
float lightDeltaY = YOUR_LIGHT.transform.position.y - topPoint.y;
float lightFlatToTopPointDistance = Vector3.Distance(lightFlatPoint, topPoint);
float shadowSize = ((YOUR_OBJECT.transform.lossyScale.y * YOUR_OBJECT_HEIGHT) / lightDeltaY) * lightFlatToTopPointDistance;
Hope it helps,
+8
source to share