So I have the Reflecting Raycast up and running. Which is displayed here:
Here is the Code:
public int maxReflectionCount = 5;
public float maxStepDistance = 200f;
void Start()
{
}
void Update()
{
Laser();
}
void Laser()
{
DrawReflectionPattern(this.transform.position + this.transform.forward * 0.75f, this.transform.forward, maxReflectionCount);
}
private void DrawReflectionPattern(Vector3 position, Vector3 direction, int reflectionsRemaining)
{
if (reflectionsRemaining == 0)
{
return;
}
Vector3 startingPosition = position;
Ray ray = new Ray(position, direction);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, maxStepDistance))
{
direction = Vector3.Reflect(direction, hit.normal);
position = hit.point;
}
else
{
position += direction * maxStepDistance;
}
Debug.DrawLine(startingPosition, position, Color.white);
DrawReflectionPattern(position, direction, reflectionsRemaining - 1);
}
What I would like help doing is overlaying a LineRenderer on top of this reflecting Raycast. I have looked up a few things online and watched some tutorials but still cant seem to get it working. Any help would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire