Getting the direction vector between two vertices rotating in space

hi,
i want to calculate the direction vector for two vertices in space correctly while holding the editing ability for the transform holding the vertices , i want to use that direction vector to calculate my procedural mesh normals
this works great when the transform position and rotation are set to zero, but as soon as i change something the normals calculated are messed up

the code that i’m using to calculate the direction vector which is the normal vector too

 void Normals( int index,  Vector3 splineVertex )
    {
        var meshVertex = _Data.Vertices[index];
        var normal = transform.InverseTransformDirection(meshVertex- splineVertex).normalized;
        _Data.Normals[index] = normal;
    }


transform is non changed


transform is changed

I don’t really understand where your input data is coming from, but if your code breaks when you change the position or rotation of an associated object, that suggests to me that one of your points is expressed in coordinates that are relative to the transform and the other is not. Subtracting two points is only meaningful if they are both in the same coordinate system.

1 Like

you are right, that was the problem, it seams like the tube vertices was in local space, i converted them to world space and problem is solved
thanx alot for the help maan,

the correct code

    void Normals( int index,  Vector3 splineVertex )
    {
        var meshVertex = transform.TransformPoint(_Data.Vertices[index]);
        var normal = transform.InverseTransformDirection(meshVertex - splineVertex) ;
        _Data.Normals[index] = normal;
    }