#might be because the cylinders are being

1 messages · Page 1 of 1 (latest)

sweet totem
#

oh is it

slim vortex
#

definitly a possibility

sweet totem
#

My heirarchy

#

so "Barrier" is the actual barrier you see, "Normal" is the white cylinder normal to the barrier & I have kept it inside a parent

#

Instantiating a shadowLinePrefab inside update(), won't it create too many projections?

slim vortex
#

indeed

sweet totem
#

So this is how I want my actual output

slim vortex
#

yeah this is certaintly difficult

sweet totem
#

anything that you know, that I should do?

#

any fixes

slim vortex
#

im digging rn looking for issues

sweet totem
#

If you take a look at this, this is what our professor used to create the projections

slim vortex
#

will do

#
for (int i = 0; i < wallControllerRef.barriersList.Count; i++)
{
    Vector3 ballPos = this.transform.localPosition;
    Vector3 barrierPos = wallControllerRef.barriersList[i].transform.position;

    // Calculate the vector from the ball to the barrier
    Vector3 toBarrier = barrierPos - ballPos;

    // Calculate the distance from the ball to the barrier along the barrier's forward direction
    float projectionDistance = Vector3.Dot(toBarrier, wallControllerRef.barriersList[i].transform.forward);

    // Calculate the projected position on the barrier
    Vector3 projectedPosition = ballPos + wallControllerRef.barriersList[i].transform.forward * projectionDistance;

    // Calculate the height (Y scale) of the shadow based on the distance between the projection and the ball
    float shadowScaleY = (projectedPosition - this.transform.localPosition).magnitude * 0.5f;

    // Instantiate a shadow object
    GameObject shadow = Instantiate(shadowLinePrefab, projectedPosition, Quaternion.identity);

    // Set the shadow's scale, making it look like a projection
    shadow.transform.localScale = new Vector3(0.02f, shadowScaleY, 0.02f);
}

i decided to calculate projectedPosition based on the distance between the ball and the barrier along the barrier's forward direction. This should provide a more accurate shadow projection on the barriers

sweet totem
#

wait

sweet totem
slim vortex
#

i dont get why

#

if you look at the shadow objects what does there scale and everything look like

sweet totem
#

If I remove the instantiate from inside the update, then this is how it looks

slim vortex
#

does it work then?

sweet totem
#

the projection is going up, not towards the plane

slim vortex
#

mmmm i see

#
for (int i = 0; i < wallControllerRef.barriersList.Count; i++)
{
    Vector3 ballPos = this.transform.localPosition;
    Vector3 normal = wallControllerRef.barriersList[i].transform.forward;
    Vector3 toBarrier = ballPos - wallControllerRef.barriersList[i].transform.position;

    // Calculate the distance from the ball to the barrier along the barrier's normal vector
    float projectionDistance = Vector3.Dot(toBarrier, normal);

    // Calculate the projected position on the barrier
    Vector3 projectedPosition = ballPos - (normal * projectionDistance);

    // Calculate the height (Y scale) of the shadow based on the distance between the projection and the ball
    float shadowScaleY = (projectedPosition - this.transform.localPosition).magnitude * 0.5f;

    // Instantiate a shadow object
    GameObject shadow = Instantiate(shadowLinePrefab, projectedPosition, Quaternion.identity);

    // Set the shadow's scale, making it look like a projection
    shadow.transform.localScale = new Vector3(0.02f, shadowScaleY, 0.02f);

    // Parent the shadow to the barrier to move with it
    shadow.transform.parent = wallControllerRef.barriersList[i].transform;
}

by projecting the ball's position onto the barrier's normal vector, which should correctly position the shadow on the barrier's surface

sweet totem
slim vortex
#

Yeah this is indeed stumping me

sweet totem
#

me too

sweet totem
slim vortex
#

honestly i have no clue im pretty stumped