- Home /
hit point not working correctly .
Hello,
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.SetPositions(laserPoints);
_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 ?
Answer by CrocsxG · Jan 19, 2018 at 08:02 AM
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 https://unity3d.com/fr/learn/tutorials/topics/2d-game-creation/sorting-layers
The Doc : https://docs.unity3d.com/ScriptReference/SortingLayer.html
Your answer
Follow this Question
Related Questions
Help with casting and drawing multiple raycast along an angle 0 Answers
Help with LineRenderer 1 Answer
Hit distance Change light range 1 Answer
How to hit two object with one raycast? 2 Answers