- Home /
Raycasting along line renderer width
I am trying to make an attack indicator. In order to do this I am using a linerenderer which follows a ray to detect collisions. The only problem is that the ray is casted along linerendere's center and I want two rays going along its margins. Any advice?
[1]: /storage/temp/187666-screenshot-2021-10-19-153127.png
Answer by Captain_Pineapple · Oct 19, 2021 at 01:00 PM
assuming that your linerenderer direction is known as Vector3 LR_Dir
then your raycast should have origin and riection as follows:
Vector3 rightOrigin = LR_Origin_Position + Vector3.Cross(LR_Dir, Vector3.up).normalized * LR_width;
Vector3 leftOrigin = LR_Origin_Position - Vector3.Cross(LR_Dir, Vector3.up).normalized * LR_width;
raycast direction should just be the same the linerenderers. To make that a bit more pretty you should first calculate the crossproduct so that you do not calculate that twice every time.
Let me know if that helped.
Your answer
Follow this Question
Related Questions
Linecast questions. 1 Answer
Help with Raycast C# 0 Answers
Only One LineRenderer Renders 0 Answers
Detecting if the object is hit by LineRenderer 1 Answer
RayCast or LineCast? 1 Answer