hit point not working correctly .


I have a problem with LineRenderer and Raycast Hit Point

I would like to make a sort of Laser from shoot position to hitpoint.

I do like this

LayerMask LayerHitable = (1 << LayerMask.NameToLayer("Player") | 1 << LayerMask.NameToLayer("Terrain"));
RaycastHit2D hit = Physics2D.Raycast(fireTurret.position, fireTurret.right, LayerHitable);
Vector3[] laserPoints = new Vector3[] { fireTurret.position, hit.point };
_lineRenderer.enabled = true;

but it game it look like this *


It’s correct on the scene preview, but not on the game preview.

How can I fix that ?

Are you using Z for your sprite positioning ?

If so, try with SortingLayer, so that all your sprite and collider will be at Z = 0

How to setup it

The Doc :