How to understand Vector3.Reflect() properly?

Why is the Result object so far away? I don’t understand the meaning of the InNormal parameter.

I’ve read it. https://docs.unity3d.com/cn/2021.3/ScriptReference/Vector3.Reflect.html,But it still confuses me and I seem to have misunderstood somewhere.

public class Reflect : MonoBehaviour
{
    public Transform A;

    public Transform B;

    public Transform InDirection;

    public Transform Result;

    // Update is called once per frame
    private void Update()
    {
        var inNormal = B.position - A.position;
        var result = Vector3.Reflect(((B.position + A.position) / 2) - InDirection.position, inNormal);
        Result.position = result;
        Debug.DrawLine(InDirection.position, result);
        Debug.DrawLine(A.position, B.position, Color.cyan);
        Debug.DrawLine(InDirection.position, (B.position + A.position) / 2, Color.yellow);
        Debug.DrawLine(result, (B.position + A.position) / 2, Color.yellow);
    }
}

The result seems so far away since it counts as a direction. It shows the “bounce” direction if you shoot a light ray from your highlighted cube down to that A/B center point. It’s like if you ask someone which way is North – they could just point with a finger, or use their whole arm and it’s the same thing: “North is that way”. Exactly where their finger tip is doesn’t matter. Once you have the result, you can easily rescale it to the length you want, or use it in a raycast to see what it hits, and so on.

To understand inNormal, hide that silver plane from the image. Now we’re bouncing off the point A/B center. Hmmm … obviously, we also need to know which way the mirror is aimed – a mirror wall facing right, or forward? a mirror floor? some other angle? inNormal is what tells Reflect which way the mirror is facing. For example, if the floor is a mirror, use Vector3.up. If the mirror is a wall facing right, use Vector3.right. If the mirror is a flat plane, p1, that the user can turn, use p1.rotation.eulerAngles.y.

using UnityEngine;

public class Reflect : MonoBehaviour
{
    public Transform A;
    public Transform B;
    public Transform InDirection;
    public Transform Result;
    private void Update()
    {
        var inNormal = (B.position - A.position).normalized;
        var result = Vector3.Reflect(A.position-InDirection.position, inNormal);
        Result.position = result+A.position;
        Debug.DrawLine(InDirection.position,A.position,Color.yellow,0.1f);
        Debug.DrawLine(A.position,Result.position,Color.yellow,0.1f);
    }
}

Thank you, I made a mistake. I forgot to add Offset.:Result.position = result+A.position;
Now, I wrote the code again and it works perfectly!

public class Reflect : MonoBehaviour
{
    public Transform InDirection;

    public Transform Plane;

    public Transform Result;

    private void Start()
    {
        Debug.Log(Plane.up);
        Debug.Log(Plane.position);
    }

    private void Update()
    {
        var inNormal = Plane.up;
        var result = Vector3.Reflect(Plane.position - InDirection.position, inNormal);
        Result.position = result + Plane.position;
        Debug.DrawLine(InDirection.position, Plane.position, Color.yellow, 0.1f);
        Debug.DrawLine(Plane.position, Result.position, Color.yellow, 0.1f);
        Debug.DrawRay(Plane.position, Plane.up * 10, Color.black);
    }
}

9382781--1312394--Snipaste_2023-10-02_12-26-41.png