I have a script that renders a laser from the front of a game object and ‘bounces’ off of gameobjects with the tag “mirror”. You can see that in the image below:
However something weird happens to the ending width of the laser after the first bounce. You can see in the image below, the ‘farthest’ out laser i.e. the last segment (marked as “4”) bounced ending width is fine. It is .075 in the beginning and .075 at the end. The other segments however taper down to 0 from .075, and it changes.
For example if I spawn a block in the lasers path on a different segment, that segment’s end width returns to .075. Image below:
The segment marked “2” ending width now remains constant where segment “1” tapers. It seems the last segment to bounce retains it’s ending width, but the previously bounced segments do not.
Any Ideas?
Code Below:
void RenderLaser(){
hitCount = 1;
laserActive = true;
teleActive = false;
curPos = transform.position;
curRot = transform.forward;
laserLine.SetVertexCount(1);
laserLine.SetPosition (0, transform.position);
while (laserActive) {
hitCount++;
laserLine.SetVertexCount(hitCount);
if (Physics.Raycast (curPos, curRot, out laserHit, range)) {
//hitCount++
curPos = laserHit.point;
curRot = Vector3.Reflect(curRot, laserHit.normal);
laserLine.SetPosition(hitCount-1, laserHit.point);
if(laserHit.collider.tag != "Mirror"){
laserActive = false;
if(laserHit.collider.tag == "WinFace"){
Debug.Log("Teleport Activated.");
teleActive = true;
}
}
} else {
//hitCount++
laserActive = false;
laserLine.SetPosition(hitCount-1, curPos+100*curRot);
}
if (hitCount > limit){
laserActive = false;
}
//END WHILE
}
}