#might be because the cylinders are being
1 messages · Page 1 of 1 (latest)
definitly a possibility
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?
indeed
https://pastebin.com/10H0Yypj
This is the latest code I am using
So this is how I want my actual output
yeah this is certaintly difficult
im digging rn looking for issues
If you take a look at this, this is what our professor used to create the projections
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
wait
this is giving the exact same output
i dont get why
if you look at the shadow objects what does there scale and everything look like
If I remove the instantiate from inside the update, then this is how it looks
does it work then?
the projection is going up, not towards the plane
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
this is how it is now. The projection line is on the red ball towards Yaxis
Yeah this is indeed stumping me
me too
how do we move ahead now?
honestly i have no clue im pretty stumped