I want a reflection of a ray but only in the X-Z axis, while the Y-axis should only allow me to adjust the height of the reflection, but have no impact on the reflection itself;
Here’s the regular reflection:
if (Physics.Raycast(ray.origin, ray.direction, out hit, remainingLength))
{
lineRenderer.positionCount += 1;
lineRenderer.SetPosition(lineRenderer.positionCount - 1, hit.point);
remainingLength -= Vector3.Distance(ray.origin, hit.point);
//temp_normal.x = ray_new.x;
ray = new Ray(hit.point, Vector3.Reflect(ray.direction, hit.normal));
Here’s my attempt, I tried making the ray origin’s y the same as the hit point’s y in hopes that it would automatically give me a X-Z reflection, alas to no avail:
var hit_2 = hit ;
//Make a new ray with the same y position as the hit point so it doesn't reflect in y
var ray_2= new Ray(new Vector3(transform.position.x,hit.point.y,transform.position.z), transform.forward);
Physics.Raycast(ray_2.origin, ray_2.direction, out hit_2, remainingLength);
lineRenderer.positionCount += 1;
lineRenderer.SetPosition(lineRenderer.positionCount - 1, hit.point);
remainingLength -= Vector3.Distance(ray.origin, hit.point);
//temp_normal.x = ray_new.x;
ray = new Ray(hit.point, Vector3.Reflect(ray_2.direction, hit.normal));
if (hit.collider.tag == "Totem")
{
//lineRenderer.material.color = new Color(0.4f, 0.9f, 0.7f, 1.0f);
break;
}