- Home /
Unity 2D -Reflecting a linerenderer
Hello, I'm fairly new to programming. I want to make a linerenderer from a gun reflect when hitting a tilted wall. And after that to bounce based on next walls rotation. How should I do that ? Should I store the hit.points in a list? I can find the line renderers origin ( this.transform.position) but can't seem to find direction. Unity only offers vector2.right left up and down.
Answer by TanselAltinel · Oct 30, 2017 at 11:11 AM
You should use Vector3.Reflect
Here's the manual on using that: https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html
But he still uses vector3.right in the parameters, I want to cast it reflected
Answer by MaxGuernseyIII · Oct 30, 2017 at 06:02 PM
I would use Vector2.Reflect. Use the direction of the weapon-fire as the direction parameter and the normal of the wall as the normal. If you don't have the normal readily available - like if you are rendering them using a line renderer and just storing vectors, you can use the right or left property of the vector you use to draw the lines.
From your picture, it seems like you want to prevent reflection when the wall is roughly perpendicular. You can use the dot product of the unit version of each vector to determine how close they are to parallel.
Really complicated stuff , as I said I'm new to unity , i know c# very well but even line renderer seems frustrating. What's the normal in vector2.reflect?