- Home /
Making a better laser
So i make a laser with the code .it work find but the problem is that when i make the line renderer width too big it look bad because when some object touch the line renderer it not really trigger the raycast so it will work like the photo [1].when the object touch block the raycast thingy it will work like photo [2].So i started to looking for something suitable for the laser.Then i saw a [2Dlighting] in the assetstore.but it just dont work in many way.Is there anyway to make a realistic laser (Sorry for my bad English)
public LineRenderer laser;
void Update()
{
Ray2D ray = new Ray2D(transform.position, transform.up);
RaycastHit2D hit2D = Physics2D.Raycast(ray.origin, transform.up);
laser.SetPosition(0,transform.position);
laser.SetPosition(1,hit2D.point);
Debug.Log(""+hit2D.collider.gameObject);
Debug.DrawLine(transform.up, hit2D.point);
}![alt text][1]
[1]: /storage/temp/145894-2.jpg
Answer by noobgamemake · Sep 08, 2019 at 07:19 PM
So i have a idea put ton of laser with this script and make it to one laser but the bad thing of this it cause lag because a line renderer with 1 width need about 50 of this to make it look smooth
void Update()
{
Ray2D ray = new Ray2D(transform.position, transform.up);
RaycastHit2D hit2D = Physics2D.Raycast(ray.origin, transform.up);
laser.SetPosition(0,transform.position);
laser.SetPosition(1,hit2D.point);
}