vectorluaroblox

How can I sunstract ONE value (z) from two vector3's between them?


Being more clear, I want to make it so the Z value of a certain vector3 subtracts with the Z value of another vector3, ONLY the Z one, this way making the X and Y values of the first vector3 stay intact, while the only modified one being the Z

These are the specific lines. If these lines do not represent an actual vector3 value, or I've made a mistake which I didn't notice, tell me.

local direction = (endPosition - startPosition).Unit * range --I want to subtract the Z value of this vector3...

    if raycast then
       local sth = raycast.Instance.Position --...with the Z value of this other one...
       local mod = vector3(Xdirval, Ydirval, Zmodval) --...and create this supossed new vector3, with the X and Y values of the "direction"'s vector3.
    end

I've learned how to get the specific value of vector3's (Z in this case), but I have no idea how to perform arihmetric between the two AND place it in a new vector3, and neither how to extract the vector3 of the items I need (sth's and direction's)


Solution

  • Simply evoke the vector position you want to use.

    if you have two vectors:

    coord1 = vector3(11, 2, 0)
    coord2 = vector3(1, 1, 1)
    

    you can do mathematical operations as follow

    print(coord1.x - coord2.x)
    >>10